1 | export { pipe as combine } from 'ts-functional-pipe';
|
2 | import { ResolvablePromise } from '@worker-tools/resolvable-promise';
|
3 | class FlushCallbackStream extends TransformStream {
|
4 | constructor(flushCallback) {
|
5 | super({ flush() { flushCallback(); } });
|
6 | }
|
7 | }
|
8 | export const flushed = () => async (ax) => {
|
9 | const x = await ax;
|
10 | const flush = new ResolvablePromise();
|
11 | const flushed = Promise.resolve(flush);
|
12 | x.effects.push(res => {
|
13 | const ref = {};
|
14 | const cb = () => flush.resolve(ref.res);
|
15 | const { status, statusText, headers, body } = res;
|
16 | ref.res = new Response(body != null
|
17 | ? body.pipeThrough(new FlushCallbackStream(cb))
|
18 | : (x.handled.then(cb), null), { status, statusText, headers });
|
19 | return ref.res;
|
20 | });
|
21 | return Object.assign(x, { flushed });
|
22 | };
|
23 |
|
\ | No newline at end of file |