Friday 24 April 2020

Library for Prioritizing Promises?

I've run into a use case that I can't seem to find a library for and I figured I'd ask here before I write one myself.Basically I need to request resource A, and if it fails, fall back and request resource B, and so on. For performance reasons, I want to fire off all the requests at once. However, I can't just use Promise.any or Promise.race because it's not guaranteed that resource A will return first. I also don't want to use Promise.all because I want to return as fast as possible, ignoring or cancelling any requests that haven't finished. I need to return if A resolves, or A rejects and B resolves, etc.Anyone know of a library that solves this elegantly?

Submitted April 25, 2020 at 01:41AM by Y33zma

No comments:

Post a Comment