tc39 / proposal-cancelable-promises

Former home of the now-withdrawn cancelable promises proposal for JavaScript
Other
376 stars 29 forks source link

`await`ing within a `finally` block of a canceled promise #7

Closed machty closed 8 years ago

machty commented 8 years ago

I'm mostly posting this issue so that it might be considered in some future spec, though I think I already know what the right answer is:

async function foo() {
  try {
    await neverResolvingFn;
  } finally {
    await neverResolvingFn;
  }
}

If a promise returned from foo() is (somehow) canceled, are there any restrictions to further (and potentially indefinitely) prolonging the lifespan of the canceled promise by awaiting within a finally block? I came across this case while working on ember-concurrency and didn't want to implement anything potential outside of the cancelable-async-await spec.

domenic commented 8 years ago

It's actually an open question how the promises returned from async functions play with cancelation. You seem to be assuming that there'd be an implicit "cancelation opportunity" inserted at every await point, but in general people do not seem to be in favor of that idea.

benjamingr commented 8 years ago

I think we discussed this and reached at the conclusion the only reasonable thing was to allow await in finally to block. https://github.com/tc39/ecmascript-asyncawait/issues/51

People are expected to be reasonable in their finally clauses.

machty commented 8 years ago

@benjamingr Now that I've seen the Stage 1 proposal, it definitely seems most consistent to allow await in finally to block since canceling a token won't actually stop execution until the next cancelIfRequested; it seems to follow that await within finally would just be yet another way to expand the time between canceling the token and stopping execution.