add $/async and $/await to racketscript/interop#293
add $/async and $/await to racketscript/interop#293stchang wants to merge 4 commits intoracketscript:masterfrom
Conversation
|
closes #253 |
|
Also addresses: #84 |
|
@gamburgm @vishesh I'm having problems making Any ideas? Do I need to change the |
Codecov Report
@@ Coverage Diff @@
## master #293 +/- ##
==========================================
+ Coverage 68.16% 68.30% +0.14%
==========================================
Files 48 48
Lines 5308 5354 +46
==========================================
+ Hits 3618 3657 +39
- Misses 1690 1697 +7
Continue to review full report at Codecov.
|
| (lambda (resolve reject) | ||
| (define image (new #js*.Image)) | ||
| (:= #js.image.crossOrigin #js"anonymous") | ||
| (:= #js.image.src (js-string data)) |
There was a problem hiding this comment.
So if I'm understanding this correctly, this won't be using async/await. And I can see why this may not work, as when we render, the image may not be ready as its getting downloaded in background. I think this is HTMLImageElement and maybe you can add an assert for complete field in render() to see if we render once image is loaded.
| (new (UrlBitmap url))) | ||
|
|
||
| ;; doesnt work, "render" is not a function" | ||
| #;($/define/async (bitmap/url url) |
There was a problem hiding this comment.
This is probably what we need to be doing, except I think bitmap/url is supposed to be a synchronous function, so this being async, will return aPromise object instead of Bitmap, and probably that's why it gives render is not a function error (since the contract is broken by it being a Promise).
Not sure what would be right way atm. Practically, its bad idea to put bitmap/url function in game-loop. It will block the frame until image is loaded in Racket too.
|
Unfortunately I think you'd have to fully commit to using
EDIT: The alternative is to make every A little unfortunate though that you'd have to make such a significant change just to allow for Let me know if the above makes any sense. |
|
That's what I was afraid of. Makes sense though, thanks. I'll keep it in mind, in case someone is looking for a small project. |
|
Just pushed something that seems to "work". It makes the I then added a One weird thing is that I couldnt find a good place to save the async objs that need resolving so right now it's just a global array in You can play around with it if you want:
If you compare the network tab in the browser for each one the async one seems a little faster, but I need to come up with some more stressful tests |
|
I think idiomatic javascript would look pretty different:
which gives the added benefit of not having to wait for images to load at the beginning that aren't needed until later (or needed at all). I can't think of a better solution than this of the top of my head without coloring all the functions async. |
No description provided.