wasmoon icon indicating copy to clipboard operation
wasmoon copied to clipboard

how to use await() in coroutine?

Open jinguo-yin opened this issue 1 year ago • 4 comments

I use coroutine.create(func) create one coroutine, using :await() in func, when JS promise is resolved,but in coroutine' await() not return;

my code is: function LedFlashFunc() local isOn = true while true do wait(1000)
print('LedFlashFunc') if isOn then local result = LedOn():await() else LedOff():await() end isOn = not isOn end end

local co = coroutine.create(func) local succeed, result = coroutine.resume(co) if not succeed then print('LUA Error: ' .. tostring(result)) end

jinguo-yin avatar Jun 10 '24 12:06 jinguo-yin

When I use this code in main thread is OK!

jinguo-yin avatar Jun 10 '24 12:06 jinguo-yin

i use async solve this program, code is: async(LedOn()) this function called yin coroutine will normal return when promise resolve ;

jinguo-yin avatar Jun 11 '24 01:06 jinguo-yin

how to block execute in coroutine, :await() only valid in doFile lua code , when coroutine.create child, in child await can not resume.

jinguo-yin avatar Jun 11 '24 14:06 jinguo-yin

I fixed it by wrapping the function I was calling in lua with async, and adding injectObjects and openingStandard Lib to createEngine

lontrr avatar Jul 29 '24 10:07 lontrr