Hey y’all!
I have a solution to the prompt… but also a couple questions that I haven’t been able to confidently resolve.
In prompt 1, we are asked the following:
animate
alice2
whenalice1
has finished, andalice3
whenalice2
has finished.
Implement something that works, but has the promise version of the “callback hell” problem we saw in our discussion of using callbacks.
a solution
a live solution is here
code in question from solution:
alice1.animate(aliceTumbling, aliceTiming);
const promise1 = alice1.animate(aliceTumbling, aliceTiming).finished;
promise1.then(() => {
const promise2 = alice2.animate(aliceTumbling, aliceTiming).finished;
promise2.then(() => {
alice3.animate(aliceTumbling, aliceTiming)
});
});
questions
-
Can the functionality of this code be accomplished using nested callbacks but without the promise variables &
.then()
? (or setTimeout ) -
If not redundant to your first answer, what might have been an implementation for this (just generally speaking) that pre-dates promises?
hope this makes sense… many thanks for your time here and elsewhere on the forum!