Promises, async functions, and requestAnimationFrame, together.

Salvador de la Puente González salva at unoyunodiez.com
Sat Apr 23 08:09:26 UTC 2016


AFAIK, that should execute `drawSomething()` once per frame. Given a frame
is each time the animatinFrame() promise resolves.

On Sat, Apr 23, 2016 at 1:38 AM, /#!/JoePea <joe at trusktr.io> wrote:

> Is it possible?
>
>  I thought maybe something like this:
>
> ```js
> function animationFrame() {
>     let resolve = null
>     const promise = new Promise(r => resolve = r)
>     window.requestAnimationFrame(resolve)
>     return promise
> }
>
> async function game() {
>     // the game loop
>     while (true) {
>         await animationFrame()
>         drawSomething()
>     }
> }
>
> game()
> ```
>
> But, I'm not sure what to expect: does the code that follows the await
> statement execute in the frame, sometimes in the frame, or never in
> the frame? What might we expect from the various browsers?
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160423/1db073a8/attachment-0001.html>


More information about the es-discuss mailing list