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

Already on GitHub? Sign in to your account

Allow when/delay to be externally resolved #52

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
Owner

scothis commented Aug 30, 2012

  • returns a full deferred instead of a promise
  • clears the timeout when resolved/rejected
@scothis scothis Allow when/delay to be externally resolved
- returns a full deferred instead of a promise
- clears the timeout when resolved/rejected
8d17d48
Owner

briancavalier commented Apr 2, 2014

The reject case is easy to achieve without adding any new functionality. The ability to short-circuit the delay by fulfilling is a bit trickier. It seems doable via any or race tho:

var p = when.promise(function(resolve, reject) {
    // control the promise's fate however you need
});
return when.race([p, when(x).delay(1000)]);

If p fulfills or rejects in < 1 second, it wins. Otherwise, delayed x wins.

How or where would you ever use this construct, tho? If there's no common use cases, and it's achievable using race, I think we should close this.

Owner

briancavalier commented Apr 15, 2014

Gonna close this for now. If there's a strong need to be able to do it, I think we should add that to the reasons to make when.race public.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment