Skip to content
Myr

feat(context): add executionCtx to Context (#326)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Hans Otto Wirtz · committed by GitHub · parent b82a75c · Browse files · 3 files+28 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+28 added−9 removed

  • other:+28 added−9 removed

3 files+28 added−9 removed

modified:src/context.ts+9 added-2 removed
modified:src/hono.ts+4 added-4 removed
158 unmodified lines
159 private matchRoute(method: string, path: string) {160 return this.router.match(method, path)161 }162163 private async dispatch(request: Request, event?: FetchEvent, env?: E): Promise<Response> {163 private async dispatch(request: Request, executionCtx?: ExecutionContext, env?: E): Promise<Response> {164 const path = getPathFromURL(request.url, this.strict)165 const method = request.method166167 const result = this.matchRoute(method, path)
1 unmodified line
169 request.paramData = result?.params170171 const handlers = result ? result.handlers : [this.notFoundHandler]172173 const c = new Context<string, E>(request, env, event, this.notFoundHandler)173 const c = new Context<string, E>(request, env, executionCtx, this.notFoundHandler)174175 const composed = compose<Context>(handlers, this.errorHandler, this.notFoundHandler)176 let context: Context177 try {
16 unmodified lines
194 async handleEvent(event: FetchEvent): Promise<Response> {195 return this.dispatch(event.request, event)196 }197198 async fetch(request: Request, env?: E, event?: FetchEvent): Promise<Response> {199 return this.dispatch(request, event, env)198 async fetch(request: Request, env?: E, executionCtx?: ExecutionContext): Promise<Response> {199 return this.dispatch(request, executionCtx, env)200 }201202 request(input: RequestInfo, requestInit?: RequestInit): Promise<Response> {203 const req = input instanceof Request ? input : new Request(input, requestInit)
9 unmodified lines
modified:README.md+15 added-3 removed
481 unmodified lines
482 c.res.headers.append('X-Debug', 'Debug message')483})484```485486### c.executionCtx487488```ts489// ExecutionContext object490app.get('/foo', async (c) => {491 c.executionCtx.waitUntil(492 c.env.KV.put(key, data)493 )494 ...495})496```497498### c.event499500```ts489// FetchEvent object501// FetchEvent object (only set when using Service Worker syntax)502app.get('/foo', async (c) => {503 c.event.waitUntil(504 c.env.KV.put(key, data)505 )
28 unmodified lines
534`app.fetch` for Cloudflare Module Worker syntax.535536```ts537export default {526 fetch(request: Request, env: Env, event: FetchEvent) {527 return app.fetch(request, env, event)538 fetch(request: Request, env: Env, ctx: ExecutionContext) {539 return app.fetch(request, env, ctx)540 },541}542```543
226 unmodified lines