Monday 24 August 2020

How do I use Promise.all with an array of Functions?

I have an array of functions, each representing a frame in an animation, and each one is periodically gets executed my Animator class (asynchronous) and removed from the list.frames = [f1, f2, f3, f4]I want to create a Promise that resolves when all these functions have been executed (when the animation is finished), but the problem is that if I do something like the followingPromise.all([new Promise(f1), new Promise(f2), new Promise(f3), new Promise(f4)])where each f resolves the promise when invoked, then all the functions get executed immediately. I don't want this, I want the functions to be executed individually only when my animator decides to.How do I create a promise that resolves when each frame of my animation has been executed?

Submitted August 25, 2020 at 01:00AM by santoso-sheep

No comments:

Post a Comment