Skip to content

Commit dea3e2a

Browse files
Using Jobs channel to call lua callback
1 parent 7aed46d commit dea3e2a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

cmd/micro/initlua.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,18 @@ func luaImportMicroShell() *lua.LTable {
105105
go func() {
106106
output, runErr := f()
107107
if cb != nil {
108-
cb(output, runErr)
108+
wrapperFunc := func(output string, args []interface{}) {
109+
errVal, ok := args[0].(error)
110+
if ok {
111+
cb(output, errVal)
112+
} else {
113+
cb(output, nil)
114+
}
115+
}
116+
var passArgs []interface{}
117+
passArgs = append(passArgs, runErr)
118+
jobFunc := shell.JobFunction{wrapperFunc, output, passArgs}
119+
shell.Jobs <- jobFunc
109120
}
110121
}()
111122
}))

0 commit comments

Comments
 (0)