pyscript: PyodideRuntime.run should not `await`
I noticed this while looking at the source code.
Runtime.run is marked async:
https://github.com/pyscript/pyscript/blob/aa85f5f5964e61f47b77cac73511d3d74c63328d/pyscriptjs/src/runtime.ts#L52-L57
But then when we call pyodide we do the following: https://github.com/pyscript/pyscript/blob/aa85f5f5964e61f47b77cac73511d3d74c63328d/pyscriptjs/src/pyodide.ts#L69-L71
Note the return await, which should probably be just a return. I’m not fully sure of the implications of doing the await here but I guess it causes code to be less parallel that it should be.
I think that it means that if we do the following:
await Promise.all([
runtime.run(src1),
runtime.run(src2),
runtime.run(src3)
]);
src1, src2 and src3 will not be executed in parallel but sequentially.
In general, I think we have a problem with our usage of async in our codebase: we use them a bit too freely and without really understanding what’s going on (or at least: personally I don’t fully understand what’s going on: if you do, please explain to me 😃).
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 18 (18 by maintainers)
The main difference is error handling. The following article may be helpful. https://dmitripavlutin.com/return-await-promise-javascript/