mirror of
https://github.com/syumai/workers.git
synced 2025-03-10 17:29:11 +00:00
remove runtimeObj from runtimecontext.New
This commit is contained in:
parent
627ed95530
commit
52a78e1789
@ -13,8 +13,8 @@ type Task func(ctx context.Context) error
|
||||
|
||||
var scheduledTask Task
|
||||
|
||||
func runScheduler(eventObj js.Value, runtimeCtxObj js.Value) error {
|
||||
ctx := runtimecontext.New(context.Background(), eventObj, runtimeCtxObj)
|
||||
func runScheduler(eventObj js.Value) error {
|
||||
ctx := runtimecontext.New(context.Background(), eventObj)
|
||||
if err := scheduledTask(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -27,13 +27,12 @@ func init() {
|
||||
panic(fmt.Errorf("invalid number of arguments given to runScheduler: %d", len(args)))
|
||||
}
|
||||
eventObj := args[0]
|
||||
runtimeCtxObj := jsutil.RuntimeContext
|
||||
var cb js.Func
|
||||
cb = js.FuncOf(func(_ js.Value, pArgs []js.Value) any {
|
||||
defer cb.Release()
|
||||
resolve := pArgs[0]
|
||||
go func() {
|
||||
err := runScheduler(eventObj, runtimeCtxObj)
|
||||
err := runScheduler(eventObj)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -24,13 +24,12 @@ func init() {
|
||||
panic(fmt.Errorf("too many args given to handleRequest: %d", len(args)))
|
||||
}
|
||||
reqObj := args[0]
|
||||
runtimeCtxObj := jsutil.RuntimeContext
|
||||
var cb js.Func
|
||||
cb = js.FuncOf(func(_ js.Value, pArgs []js.Value) any {
|
||||
defer cb.Release()
|
||||
resolve := pArgs[0]
|
||||
go func() {
|
||||
res, err := handleRequest(reqObj, runtimeCtxObj)
|
||||
res, err := handleRequest(reqObj)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -53,7 +52,7 @@ func (c *appCloser) Close() error {
|
||||
}
|
||||
|
||||
// handleRequest accepts a Request object and returns Response object.
|
||||
func handleRequest(reqObj js.Value, runtimeCtxObj js.Value) (js.Value, error) {
|
||||
func handleRequest(reqObj js.Value) (js.Value, error) {
|
||||
if httpHandler == nil {
|
||||
return js.Value{}, fmt.Errorf("Serve must be called before handleRequest.")
|
||||
}
|
||||
@ -61,7 +60,7 @@ func handleRequest(reqObj js.Value, runtimeCtxObj js.Value) (js.Value, error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ctx := runtimecontext.New(context.Background(), reqObj, runtimeCtxObj)
|
||||
ctx := runtimecontext.New(context.Background(), reqObj)
|
||||
req = req.WithContext(ctx)
|
||||
reader, writer := io.Pipe()
|
||||
w := &jshttp.ResponseWriter{
|
||||
|
@ -7,12 +7,10 @@ import (
|
||||
|
||||
type (
|
||||
contextKeyTriggerObj struct{}
|
||||
contextKeyRuntimeObj struct{}
|
||||
)
|
||||
|
||||
func New(ctx context.Context, triggerObj, runtimeObj js.Value) context.Context {
|
||||
func New(ctx context.Context, triggerObj js.Value) context.Context {
|
||||
ctx = context.WithValue(ctx, contextKeyTriggerObj{}, triggerObj)
|
||||
ctx = context.WithValue(ctx, contextKeyRuntimeObj{}, runtimeObj)
|
||||
return ctx
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user