gopher-lua icon indicating copy to clipboard operation
gopher-lua copied to clipboard

coroutine status is running after yield

Open joesonw opened this issue 5 years ago • 0 comments

  1. What version of GopherLua are you using? :
  2. What version of Go are you using? : 1.14.2
  3. What operating system and processor architecture are you using? : MacOS X Mojave
  4. 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)
	}
}
  1. What did you expect to see? :
suspended
hello
suspended
hello
  1. What did you see instead? :
suspended
hello
running

joesonw avatar Jul 09 '20 06:07 joesonw