Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

awaits on complete fn #7

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/endpoint-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ export class EndpointHarness {
passThroughOnException: () => { }
};
this.reqCtx = new Context(this.req, {}, this.ctx, {});

// extract the context reference
this.endpoint.use((ctx: Context, next: Function) => {
this.reqCtx = ctx;
next();
});
}

use(fn: Function): this {
Expand All @@ -66,12 +60,18 @@ export class EndpointHarness {
const defaultEnv = env || {};
const defaultCtx = ctx || this.ctx

// extract the final context reference
this.endpoint.use(async (ctx: Context, next: Function) => {
this.reqCtx = ctx;
await next();
});

return this.endpoint.fetch(defaultRequest, defaultEnv, defaultCtx);
}

async onAfterComplete(fn: Function) {
await this.queue.allComplete();
fn(this.reqCtx);
await fn(this.reqCtx);
}
}

Expand Down