feat(app): pass context to start process
This commit is contained in:
@ -13,7 +13,7 @@ import (
|
||||
|
||||
var (
|
||||
ErrFuncDoesNotExist = errors.New("function does not exist")
|
||||
ErUnknownError = errors.New("unknown error")
|
||||
ErrUnknownError = errors.New("unknown error")
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
@ -90,7 +90,7 @@ func (s *Server) Exec(ctx context.Context, callableOrFuncname any, args ...inter
|
||||
if ok {
|
||||
logger.Error(ctx, "recovered runtime error", logger.E(errors.WithStack(revoveredErr)))
|
||||
|
||||
err = errors.WithStack(ErUnknownError)
|
||||
err = errors.WithStack(ErrUnknownError)
|
||||
|
||||
return
|
||||
}
|
||||
@ -162,7 +162,7 @@ func (s *Server) WaitForPromise(promise *goja.Promise) goja.Value {
|
||||
return value
|
||||
}
|
||||
|
||||
func (s *Server) Start() error {
|
||||
func (s *Server) Start(ctx context.Context) error {
|
||||
s.loop.Start()
|
||||
|
||||
var err error
|
||||
@ -171,7 +171,7 @@ func (s *Server) Start() error {
|
||||
rt.SetFieldNameMapper(goja.TagFieldNameMapper("goja", true))
|
||||
rt.SetRandSource(createRandomSource())
|
||||
|
||||
if err = s.initModules(rt); err != nil {
|
||||
if err = s.initModules(ctx, rt); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
}
|
||||
})
|
||||
@ -186,7 +186,7 @@ func (s *Server) Stop() {
|
||||
s.loop.Stop()
|
||||
}
|
||||
|
||||
func (s *Server) initModules(rt *goja.Runtime) error {
|
||||
func (s *Server) initModules(ctx context.Context, rt *goja.Runtime) error {
|
||||
modules := make([]ServerModule, 0, len(s.factories))
|
||||
|
||||
for _, moduleFactory := range s.factories {
|
||||
@ -206,9 +206,9 @@ func (s *Server) initModules(rt *goja.Runtime) error {
|
||||
continue
|
||||
}
|
||||
|
||||
logger.Debug(context.Background(), "initializing module", logger.F("module", initMod.Name()))
|
||||
logger.Debug(ctx, "initializing module", logger.F("module", initMod.Name()))
|
||||
|
||||
if err := initMod.OnInit(rt); err != nil {
|
||||
if err := initMod.OnInit(ctx, rt); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/dop251/goja"
|
||||
)
|
||||
|
||||
@ -13,5 +15,5 @@ type ServerModule interface {
|
||||
|
||||
type InitializableModule interface {
|
||||
ServerModule
|
||||
OnInit(rt *goja.Runtime) error
|
||||
OnInit(ctx context.Context, rt *goja.Runtime) error
|
||||
}
|
||||
|
Reference in New Issue
Block a user