Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Bluebird.propsRace #1644

Open
knoid opened this issue Apr 10, 2020 · 0 comments
Open

Proposal: Bluebird.propsRace #1644

knoid opened this issue Apr 10, 2020 · 0 comments

Comments

@knoid
Copy link

knoid commented Apr 10, 2020

I'd find it useful to have an easy way to know which promise "won the race". A simple usage example would be to show the loading spinner only when the request took more than X milliseconds.

const { stillWaiting } = await Bluebird.propsRace({
  request: api.get('/something'),
  stillWaiting: Bluebird.delay(200, true),
});
if (stillWaiting) {
  showLoading();
}

A possible implementation could be:

Bluebird.raceProps = function raceProps(props) {
  const raceArray = Object.entries(props)
    .map(([key, resolvable]) => Bluebird.resolve(resolvable).then(
      (value) => ({ [key]: value }),
    ));
  return Bluebird.race(raceArray);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant