mirror of
https://github.com/syumai/workers.git
synced 2025-03-11 01:39:11 +00:00
F: add passThroughOnException
This commit is contained in:
parent
c0f7b90059
commit
a9fa550371
@ -12,9 +12,8 @@ import (
|
||||
// It accepts an asynchronous task which the Workers runtime will execute before the handler terminates but without blocking the response.
|
||||
// see: https://developers.cloudflare.com/workers/runtime-apis/fetch-event/#waituntil
|
||||
func WaitUntil(ctx context.Context, task func()) {
|
||||
executionContext := cfruntimecontext.GetExecutionContext(ctx)
|
||||
|
||||
executionContext.Call("waitUntil", jsutil.NewPromise(js.FuncOf(func(this js.Value, pArgs []js.Value) any {
|
||||
exCtx := cfruntimecontext.GetExecutionContext(ctx)
|
||||
exCtx.Call("waitUntil", jsutil.NewPromise(js.FuncOf(func(this js.Value, pArgs []js.Value) any {
|
||||
resolve := pArgs[0]
|
||||
go func() {
|
||||
task()
|
||||
@ -23,3 +22,11 @@ func WaitUntil(ctx context.Context, task func()) {
|
||||
return js.Undefined()
|
||||
})))
|
||||
}
|
||||
|
||||
// PassThroughOnException prevents a runtime error response when the Worker script throws an unhandled exception.
|
||||
// Instead, the request forwards to the origin server as if it had not gone through the worker.
|
||||
// see: https://developers.cloudflare.com/workers/runtime-apis/fetch-event/#passthroughonexception
|
||||
func PassThroughOnException(ctx context.Context) {
|
||||
exCtx := cfruntimecontext.GetExecutionContext(ctx)
|
||||
exCtx.Call("passThroughOnException")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user