fix(app): use event loop runtime for every operations
All checks were successful
arcad/edge/pipeline/head This commit looks good
All checks were successful
arcad/edge/pipeline/head This commit looks good
This commit is contained in:
@ -15,10 +15,7 @@ const (
|
||||
defaultTimeout = 30 * time.Second
|
||||
)
|
||||
|
||||
type Module struct {
|
||||
ctx context.Context
|
||||
server *app.Server
|
||||
}
|
||||
type Module struct{}
|
||||
|
||||
func (m *Module) Name() string {
|
||||
return "cast"
|
||||
@ -54,7 +51,7 @@ func (m *Module) refreshDevices(call goja.FunctionCall, rt *goja.Runtime) goja.V
|
||||
panic(rt.ToValue(errors.WithStack(err)))
|
||||
}
|
||||
|
||||
promise := m.server.NewPromise()
|
||||
promise := app.NewPromiseProxyFrom(rt)
|
||||
|
||||
go func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
@ -102,7 +99,7 @@ func (m *Module) loadUrl(call goja.FunctionCall, rt *goja.Runtime) goja.Value {
|
||||
panic(rt.ToValue(errors.WithStack(err)))
|
||||
}
|
||||
|
||||
promise := m.server.NewPromise()
|
||||
promise := app.NewPromiseProxyFrom(rt)
|
||||
|
||||
go func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
@ -121,7 +118,7 @@ func (m *Module) loadUrl(call goja.FunctionCall, rt *goja.Runtime) goja.Value {
|
||||
promise.Resolve(nil)
|
||||
}()
|
||||
|
||||
return m.server.ToValue(promise)
|
||||
return rt.ToValue(promise)
|
||||
}
|
||||
|
||||
func (m *Module) stopCast(call goja.FunctionCall, rt *goja.Runtime) goja.Value {
|
||||
@ -137,7 +134,7 @@ func (m *Module) stopCast(call goja.FunctionCall, rt *goja.Runtime) goja.Value {
|
||||
panic(rt.ToValue(errors.WithStack(err)))
|
||||
}
|
||||
|
||||
promise := m.server.NewPromise()
|
||||
promise := app.NewPromiseProxyFrom(rt)
|
||||
|
||||
go func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
@ -156,7 +153,7 @@ func (m *Module) stopCast(call goja.FunctionCall, rt *goja.Runtime) goja.Value {
|
||||
promise.Resolve(nil)
|
||||
}()
|
||||
|
||||
return m.server.ToValue(promise)
|
||||
return rt.ToValue(promise)
|
||||
}
|
||||
|
||||
func (m *Module) getStatus(call goja.FunctionCall, rt *goja.Runtime) goja.Value {
|
||||
@ -172,7 +169,7 @@ func (m *Module) getStatus(call goja.FunctionCall, rt *goja.Runtime) goja.Value
|
||||
panic(rt.ToValue(errors.WithStack(err)))
|
||||
}
|
||||
|
||||
promise := m.server.NewPromise()
|
||||
promise := app.NewPromiseProxyFrom(rt)
|
||||
|
||||
go func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
@ -191,7 +188,7 @@ func (m *Module) getStatus(call goja.FunctionCall, rt *goja.Runtime) goja.Value
|
||||
promise.Resolve(status)
|
||||
}()
|
||||
|
||||
return m.server.ToValue(promise)
|
||||
return rt.ToValue(promise)
|
||||
}
|
||||
|
||||
func (m *Module) parseTimeout(rawTimeout string) (time.Duration, error) {
|
||||
@ -214,8 +211,6 @@ func (m *Module) parseTimeout(rawTimeout string) (time.Duration, error) {
|
||||
|
||||
func CastModuleFactory() app.ServerModuleFactory {
|
||||
return func(server *app.Server) app.ServerModule {
|
||||
return &Module{
|
||||
server: server,
|
||||
}
|
||||
return &Module{}
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ func TestCastModuleRefreshDevices(t *testing.T) {
|
||||
t.Error(errors.WithStack(err))
|
||||
}
|
||||
|
||||
promise, ok := server.IsPromise(result)
|
||||
promise, ok := app.IsPromise(result)
|
||||
if !ok {
|
||||
t.Fatal("expected promise")
|
||||
}
|
||||
|
Reference in New Issue
Block a user