Skip to content

Conversation

@clue
Copy link
Member

@clue clue commented Jul 4, 2015

  • Add cancellation support for resolve() and reject()
    • Remove internal timers
    • Reject resulting promise with RuntimeException
  • Add cancellation support for timeout()
  • Cancellation of input promise for timeout() is not affected

Closes #3

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably be removed, relying on the default cancelling behaviour of the input promise.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default cancelling behaviour of the input promise

I'm not sure I follow, but how can we rely on its handling?

It's my understanding that the input promise can support cancellation, but we can't really rely on its outcome.
Also, I'm not sure about the rejection value?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in this case, it is safe to use the default cancellation flow because the promise is cancelled before the timer rejects the promise.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide a gist / PR that exhibits this? Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to gist this. We should simply do not take responsibility for the cancelling behaviour (which is not necessarily rejection) from the root promise. Why reject here if the root promise decides to do something else? We should only recject if an actual timeout occurs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting idea – albeit different to what we've discussed in #3 so far :)

I'll take a look at this and see how this works out.

This has some different implications than the current implementation. In particular, we can no longer rely on the outcome of the cancel() call (though this may not necessarily be a bad thing as you've pointed out).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is different. Sorry for raising this here instead of the original issue. The idea for the current cancellation implementation has been to not give consumers the ability to reject a promise through the cancel() call but leave all responsibilities to the promise producer.

I'd vote for leaving all responsibilities to the root promise and only take them over (reject) once the timeout occurs. This means, as long as no timout occurs, everything works as we never called timeout() at all.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea for the current cancellation implementation has been to not give consumers the ability to reject a promise through the cancel() call but leave all responsibilities to the promise producer.

I think this makes perfect sense, thanks for the discussion! 👍

I've just filed #18 as a better alternative to this PR.

@clue clue mentioned this pull request Jul 5, 2015
@clue clue mentioned this pull request Feb 17, 2016
@clue clue closed this Feb 17, 2016
@clue clue deleted the cancellation branch February 17, 2016 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Promise cancellation

3 participants