|
|
|
@ -23,7 +23,7 @@ type Server struct {
|
|
|
|
|
modules []ServerModule
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *Server) ExecFuncByName(ctx context.Context, funcName string, args ...interface{}) (any, error) {
|
|
|
|
|
func (s *Server) ExecFuncByName(ctx context.Context, funcName string, args ...any) (any, error) {
|
|
|
|
|
ctx = logger.With(ctx, logger.F("function", funcName), logger.F("args", args))
|
|
|
|
|
|
|
|
|
|
ret, err := s.Exec(ctx, funcName, args...)
|
|
|
|
@ -34,9 +34,9 @@ func (s *Server) ExecFuncByName(ctx context.Context, funcName string, args ...in
|
|
|
|
|
return ret, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *Server) Exec(ctx context.Context, callableOrFuncname any, args ...interface{}) (any, error) {
|
|
|
|
|
func (s *Server) Exec(ctx context.Context, callableOrFuncname any, args ...any) (any, error) {
|
|
|
|
|
type result struct {
|
|
|
|
|
value goja.Value
|
|
|
|
|
value any
|
|
|
|
|
err error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -110,7 +110,7 @@ func (s *Server) Exec(ctx context.Context, callableOrFuncname any, args ...inter
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
done <- result{
|
|
|
|
|
value: value,
|
|
|
|
|
value: value.Export(),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.Debug(ctx, "executed callable", logger.F("callable", callableOrFuncname), logger.F("duration", time.Since(start).String()))
|
|
|
|
@ -129,13 +129,11 @@ func (s *Server) Exec(ctx context.Context, callableOrFuncname any, args ...inter
|
|
|
|
|
return nil, errors.WithStack(result.err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
value := result.value
|
|
|
|
|
|
|
|
|
|
if promise, ok := IsPromise(value); ok {
|
|
|
|
|
if promise, ok := isPromise(result.value); ok {
|
|
|
|
|
return s.waitForPromise(promise), nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value.Export(), nil
|
|
|
|
|
return result.value, nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|