From 48e16bc1264aab6c5397880c3eb92c17e1e837fd Mon Sep 17 00:00:00 2001 From: unwox Date: Mon, 23 Dec 2024 22:31:56 +0600 Subject: small improvements --- worker.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'worker.go') diff --git a/worker.go b/worker.go index e7d76e4..c0ccc65 100644 --- a/worker.go +++ b/worker.go @@ -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) } -- cgit v1.2.3