My situation is that I have a promise waiting for an object to finish animating, but there are times when the animation needs to be stopped, and the promise fulfilled. For example...
const p = new Promise(resolve => {
s.animate({
...
call: () => {
console.log("s.animate done");
resolve();
}
})
});
This works as long as the animation completes normally. But, I need to also have the promise resolve (or reject) if the animation ends abnormally, such as through a .stopAnimate(). It seems there is no callback upon stopAnimate()?
The code that never completes is...
await Promise.allSettled([animations]);
...where animations is an array of stuff like in the first block.
Hi @pettis thanks for the reply. My architecture doesn't have the stopAnimate within the promise. The need to stopAnimate/resolve/reject is externally driven. Also, it's not just that I want the promise to return, but also that I want to put clean-up code in case stopAnimate is called, similar to the call: FN property, but something like stopCall: FN.
So not unlike what you've provided, which I very much appreciate, and notwithstanding an actual stopCall property on animate, I think I may need to do something more like this...
In general, we do not put events on methods as we assume whatever you wanted to do in the event you can just do the line after the method call. It also helps us not trigger an event twice which historically happened once or twice. Callbacks may be a little different... and I don't think it would hurt to provide a stopped callback... would we need a paused callback and an unpaused callback... so that then adds to the parameters. Let's all give it some thought and see if some other way works or if we should do the callback.