Jump to content
Search Community

Promise.all dont resolve when overwrite

jonForum test
Moderator Tag

Recommended Posts

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

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!

  • Thanks 1
Link to comment
Share on other sites

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. 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...