vlki / refresh-fetch

Wrapper around fetch capable of graceful authentication token refreshing.
MIT License
84 stars 12 forks source link

feature request: handling parallel requests #23

Open dragoonzx opened 3 years ago

dragoonzx commented 3 years ago

Can we have something like refreshQueue with requests that will proceed after getting token?)

mamsoudi commented 3 years ago

I believe it already does that according to both the description and also the code.

I quote from the readme file:

And now you want to have the original request repeated. And also if there is request called during the refreshing, you don't want to start refreshing second time, but you just want to wait for the first refresh to complete and use the new token.

From what I've seen in the source, although there's no queue per se, other promises are not returned until the token has successfully refreshed.

dragoonzx commented 3 years ago

Nope, it doesn`t handle cases like Promise.all :(

One of the forks actually handles it somehow https://github.com/TwilightOwl/refresh-fetch/commits/main and it works

vlki commented 3 years ago

Hey, sorry to hear that it does not work properly with Promise.all for you. I just tried it myself with Promise.all, basically I let the token expire and then run several API calls and it works as expected -- all the calls fail with "token expired" error, then one call for refresh token is made and when the token is refreshed, all the failed calls are retried with success.

There might be problem because of the race condition I guess though. Could you post a piece of code where it does not work as you want?