jonForum Posted December 12, 2023 Share Posted December 12, 2023 hi, i have issue with promise, is there any way to resolve `await Promise.all([ tl1 ])` when we overwrite a instance properties ? Some of my promise wait for animations but never resolve because they get crush somewhere in another child actions. ```ts gsap.defaults({ overwrite: 'auto', onInterrupt:function() { this.progress( 1 ); // force progress 100%, kill la promise pour les async await. } }); // test gsap promise all setTimeout( async () => { console.log( '💚' ); const obj = { x:0 }; const tl1 = gsap.timeline().to( obj, { x:8 }); const tl2 = gsap.timeline().to( obj, { x:5 }); // comment me for resolve Promise.all setTimeout( async () => { await tl1; console.log( '💚1' ); await Promise.all([ tl1 ]); console.log( '💚2' ); // never fired if tl2 executed }, 10 ); }, 1000 ); ``` is a `onInterrupt` bug ? or maybe we have another global cb for handle those case ? thanks Link to comment Share on other sites More sharing options...
Rodrigo Posted December 12, 2023 Share Posted December 12, 2023 Hi, By default a GSAP Tween/Timeline doesn't return a promise, it returns a GSAP instance. You have to attach the then() method in order to treat it as a promise inside an async/await block: const tl1 = gsap.timeline().then(() => {}); const tl2 = gsap.timeline(); console.log(tl1);// -> Promise {<pending>} console.log(tl2);// -> Timeline {vars: {…}, _delay: 0, _repeat: 0, _ts: 1, _dur: 0, …} This seems to work the way you intend: gsap.defaults({ overwrite: 'auto', onInterrupt:function() { this.progress( 1 ); // force progress 100%, kill la promise pour les async await. } }); // test gsap promise all setTimeout( async () => { console.log( '💚' ); const obj = { x:0 }; const tl1 = gsap.timeline().to( obj, { x:8 }).then(() => {}); const tl2 = gsap.timeline().to( obj, { x:5 }).then(() => {}); // comment me for resolve Promise.all setTimeout( async () => { await tl1; console.log( '💚1' ); await Promise.all([ tl1 ]); console.log( '💚2' ); // never fired if tl2 executed }, 10 ); }, 1000 ); Hopefully this helps. Happy Tweening! 1 Link to comment Share on other sites More sharing options...
GreenSock Posted December 12, 2023 Share Posted December 12, 2023 I see the problem - it was a very specific edge case where you had a timeline with a zero duration (your tween got overwritten, so it was removed from the timeline, making it empty), the timeline already completed, and then you tried to resolve the promise. In that case the progress of the [empty] timeline was reporting a progress of 0. Also, just to be clear, overwriting is for tweens, not timelines. Same for onInterrupt(). All that being said, I it should be fixed in the next patch (due out in the next week or so). Thanks for letting us know. 1 1 Link to comment Share on other sites More sharing options...
jonForum Posted December 12, 2023 Author Share Posted December 12, 2023 oki thank everyone https://github.com/greensock/GSAP/issues/565 @Rodrigo yes it help thanks for your time , i will use your solution until jack fix the libs 2 Link to comment Share on other sites More sharing options...
GreenSock Posted December 15, 2023 Share Posted December 15, 2023 The fix has been officially published in 3.12.4. ✅ 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now