remove runtimeObj from runtimecontext.New

This commit is contained in:
syumai 2024-04-17 00:56:35 +09:00
parent 627ed95530
commit 52a78e1789
3 changed files with 7 additions and 11 deletions

View File

@ -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)
}

View File

@ -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{

View File

@ -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
}