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

Commit

Permalink
awaits on complete fn (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonfriesen authored Jan 11, 2024
1 parent 4ecad5b commit b9a1e71
Showing 1 changed file with 7 additions and 7 deletions.
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

0 comments on commit b9a1e71

Please sign in to comment.