-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Awaiting multiple asynchronous calls in callback function #105
Comments
Here is how I use it: https://github.com/ceifa/demoon/blob/main/src/std.lua |
I don't know if this is the same issue, but I managed to trigger a use-after-free issue when using multiple async calls grouped by import { LuaFactory } from 'wasmoon';
const factory = new LuaFactory();
const L = await factory.createEngine();
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
L.global.set('sleep', sleep);
const results = await Promise.all([
L.doString('sleep(400):await(); return 1'),
sleep(100)
.then(() => L.doString('sleep(500):await(); return 2')),
sleep(200)
.then(() => L.doString('sleep(3000):await(); return 3')),
sleep(300)
.then(() => L.doString('sleep(1000):await(); collectgarbage(); return 4')),
]);
console.log(results); Basically, the Line 81 in 87c783a
Line 97 in 87c783a
The code snippet above does the following:
Maybe |
It seems I cannot reproduce the issue anymore. I thought it would be easy to reproduce, but I've done some testing where I combined multiple callback functions with asynchronous calls, and the original workaround from the readme worked fine every time. I guess my case was either very specific (which I cannot recreate now), or I made some other mistake somewhere. |
I'm using the workaround from the readme to allow using await in callback functions. It works well when there is only one asynchronous call inside the callback function. But if there are more, it will produce an infinite loop after the first call is finished. I managed to find a solution for this, so I thought I would post it here. Also I'm not very experienced with coroutines, so maybe you could tell me if my solution is acceptable.
Basically what I did was to extend the condition at the end of the local "step" function.
Before:
After:
The text was updated successfully, but these errors were encountered: