Reports whether a value is thenable, by the same duck-typed test the
platform serve layers use rather than instanceof Promise.
The distinction is load-bearing on the request path (M87). instanceof
asks whether a value was built by this realm'sPromise constructor, and
answers false for a promise from another realm (a vm context, a worker)
and for every userland promise library. Those values satisfy
RouteHandler's declared Promise<HandlerResult> structurally,
so TypeScript accepts them and only the runtime check can tell them apart —
and a request path that treats one as "already finished" sends the response
while the handler is still running, with no error anywhere.
Both @setu-ts/kernel and @setu-ts/runtime decide "did this need
awaiting?" on the hot path, so the rule lives here and neither can drift
from the other about what counts as asynchronous.
Type Parameters
T
The value the thenable resolves to, preserved by the guard so
the narrowed branch keeps its type rather than widening to unknown
constresult = handler(ctx); // `Promise.resolve` returns a native promise unchanged, and adopts a // foreign thenable, so the fast path allocates nothing. returnisPromiseLike(result) ? Promise.resolve(result) : undefined;
Reports whether a value is thenable, by the same duck-typed test the platform serve layers use rather than
instanceof Promise.The distinction is load-bearing on the request path (M87).
instanceofasks whether a value was built by this realm'sPromiseconstructor, and answersfalsefor a promise from another realm (avmcontext, a worker) and for every userland promise library. Those values satisfyRouteHandler's declaredPromise<HandlerResult>structurally, so TypeScript accepts them and only the runtime check can tell them apart — and a request path that treats one as "already finished" sends the response while the handler is still running, with no error anywhere.Both
@setu-ts/kerneland@setu-ts/runtimedecide "did this need awaiting?" on the hot path, so the rule lives here and neither can drift from the other about what counts as asynchronous.