summaryrefslogtreecommitdiff
path: root/worker.go
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2024-12-23 22:31:56 +0600
committerunwox <me@unwox.com>2024-12-23 22:31:56 +0600
commit48e16bc1264aab6c5397880c3eb92c17e1e837fd (patch)
tree7e8ef1331da309824f21a8d8d757e56af667fbdf /worker.go
parent7a052182c038dab42000ca3ea0cf7de601eeb07b (diff)
small improvements
Diffstat (limited to 'worker.go')
-rw-r--r--worker.go24
1 files changed, 14 insertions, 10 deletions
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)
}