4 ms·
I was trying to make coroutines work through the javascript event loop, such that you could basically "await" any javascript Promise (or wrap a Promise in an aw
by bayesian_horse 8y ago
I was trying to make coroutines work through the javascript event loop, such that you could basically "await" any javascript Promise (or wrap a Promise in an awaitable).
So you'd have things like 'await sleep(1)' which would be implemented with a Promise and setTimeout. Or 'await fetch("/api/v1/list")'.
Unfortunately I haven't gotten very far yet.
- bijection 8y agoI'm pretty sure you can await any javascript Promise! For example, running `await Promise.resolve(3)` in Chrome's js console prints `3`.
- alexkavon 8y agoAlso MDN has a fantastic Promise article with examples about wrapping a function with a promise.[0] [0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- JonathonW 8y agoIt's a little unclear, but I think he wants to integrate Python (Pyodide) coroutines into the JS event loop-- so async/await of Python code works seamlessly in the browser, and you can await Python code from within JS (and vice versa). Any JS Promise is awaitable from JS; JS async/await is (more or less) syntactic sugar on top of promises.
- bayesian_horse 8y agoSorry, I meant to use "await" in Python to await Javascript Promises.
- KenoFischer 8y agoMy preferred way to do this would be a compiler pass that rewrites everything to use the explicitly managed stack. I had started on writing that transform, but ran out of time. That's currently the major blocker for making the Julia/Iodide integration work well.