@worker-tools/middleware
Version:
A suite of standalone HTTP server middlewares for Worker Runtimes.
23 lines • 874 B
JavaScript
export { pipe as combine } from 'ts-functional-pipe';
import { ResolvablePromise } from '@worker-tools/resolvable-promise';
class FlushCallbackStream extends TransformStream {
constructor(flushCallback) {
super({ flush() { flushCallback(); } });
}
}
export const flushed = () => async (ax) => {
const x = await ax;
const flush = new ResolvablePromise();
const flushed = Promise.resolve(flush);
x.effects.push(res => {
const ref = {};
const cb = () => flush.resolve(ref.res);
const { status, statusText, headers, body } = res;
ref.res = new Response(body != null
? body.pipeThrough(new FlushCallbackStream(cb))
: (x.handled.then(cb), null), { status, statusText, headers });
return ref.res;
});
return Object.assign(x, { flushed });
};
//# sourceMappingURL=flushed.js.map