Ah, I think the reason that this animation loop using promises works is
because promise handlers resolve in the next microtask after the current
macrotask. I believe that the animation frame fires in what is essentially
a macrotask, then immediately after this macrotask the resolution of the
`anima
This is definitely interesting stuff. Have you considered rewriting this so
that it only uses generators? If you did then you could test natively in
Chrome and see if you get the same results.
- Matthew Robb
On Sat, Apr 23, 2016 at 7:01 PM, /#!/JoePea wrote:
> Just to show a little more detail
Note that there is no guarantee that the `then` handlers (after the await)
will fire in the same loop since they defer execution on their own and
might defer it further.
In practice I assume they'll probe to see if they need to actually schedule
asynchronously or the constructed promise is already
Just to show a little more detail, here's a screenshot that shows that
the logic of the while-loop version of my animation loop fires inside
each animation frame. I've zoomed out and we can see there's nothing
fired between the frames:
https://cloud.githubusercontent.com/assets/297678/14764323/c28
Alright, I did an experiment, and I'm really surprised at the results!
Apparently, the logic (what would be drawSomething() in my previous
example) is fired within the frame!!
So, let me show you my original method for starting an animation loop.
I'm working on a 3D project at http://infamous.io.
On 4/23/16 4:09 AM, Salvador de la Puente González wrote:
AFAIK, that should execute `drawSomething()` once per frame. Given a
frame is each time the animatinFrame() promise resolves.
What's not obvious to me is whether it will execute it before the actual
paint for the frame (i.e. before or r
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 wrote:
> Is it possible?
>
> I thought maybe something like this:
>
> ```js
> function animationFrame() {
> let resolve =
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) {
8 matches
Mail list logo