gopher-lua
gopher-lua copied to clipboard
coroutine status is running after yield
- What version of GopherLua are you using? :
- What version of Go are you using? : 1.14.2
- What operating system and processor architecture are you using? : MacOS X Mojave
- What did you do? :
func main() {
L := lua.NewState()
s := make(chan os.Signal, 1)
signal.Notify(s, os.Interrupt)
ch := make(chan struct{}, 1)
L.SetGlobal("sleep", L.NewFunction(func(L *lua.LState) int {
cb := L.CheckFunction(1)
go func() {
time.Sleep(time.Second)
<-ch
die(L.CallByParam(lua.P{
Fn: cb,
Protect: true,
}, lua.LString("hello")))
ch <- struct{}{}
}()
return 0
}))
die(L.DoString(`
function async(f)
local co = coroutine.running()
local result
f(function(res)
result = res
print(coroutine.status(co))
coroutine.resume(co)
end)
coroutine.yield()
return result
end
local co = coroutine.create(function()
print(async(sleep))
print(async(sleep))
end)
coroutine.resume(co)
`))
ch <- struct{}{}
<-s
}
func die(err error) {
if err != nil {
panic(err)
}
}
- What did you expect to see? :
suspended
hello
suspended
hello
- What did you see instead? :
suspended
hello
running