diff options
| author | unwox <me@unwox.com> | 2024-12-23 22:31:56 +0600 |
|---|---|---|
| committer | unwox <me@unwox.com> | 2024-12-23 22:31:56 +0600 |
| commit | 48e16bc1264aab6c5397880c3eb92c17e1e837fd (patch) | |
| tree | 7e8ef1331da309824f21a8d8d757e56af667fbdf /worker.go | |
| parent | 7a052182c038dab42000ca3ea0cf7de601eeb07b (diff) | |
small improvements
Diffstat (limited to 'worker.go')
| -rw-r--r-- | worker.go | 24 |
1 files changed, 14 insertions, 10 deletions
@@ -40,7 +40,7 @@ type Worker struct { routes map[string]LuaRef started bool mu sync.Mutex - repl *LuaRef + evalFn *LuaRef } // NewWorker creates a new instance of Worker type. @@ -221,12 +221,14 @@ outer: if !ok { break outer } - resCh <- NewCoroutine(func(yield func(), resume func() bool) { - handle(r, yield, func () bool { - resCh <- resume - return true - }) - }) + resCh <- NewCoroutine( + func(yield func(), resume func() bool) { + handle(r, yield, func () bool { + resCh <- resume + return true + }) + }, + ) case resume, ok := <-resCh: // coroutine executor if !ok { @@ -237,12 +239,14 @@ outer: } } -// Eval evaluates the code in the Lua context. +// Eval evaluates the code in the Lua context. Not safe for execution when +// there are requests in the processing queue, only meant for development +// purposes. func (w *Worker) Eval(code string) error { w.mu.Lock() defer w.mu.Unlock() - if w.repl != nil { - w.lua.PushFromRef(*w.repl) + if w.evalFn != nil { + w.lua.PushFromRef(*w.evalFn) w.lua.PushString(code) return w.lua.PCall(1, 0, 0) } |
