1 of 8

Cancellation Update

Ron Buckton, Microsoft Corporation

2 of 8

Motivations

  • Consistent approach to cancellation across platforms.
  • Means to support possible future proposals for:
    • ‘Promise.prototype.then’ cancellation
    • ‘import’ call expression cancellation

3 of 8

Blocking Issue

  • ECMAScript cancellation primitive duplicative of WHATWG AbortSignal
  • WHATWG AbortSignal depends on EventTarget and cannot easily be adopted by ECMAScript at this time.

4 of 8

Proposed Solution

  • Issue: https://github.com/tc39/proposal-cancellation/issues/22
  • Define “Cancellation Protocol” instead of “Cancellation Primitive”
    • Allows community to innovate cancellation.
    • Allows 3rd-party libraries to interop with cancellation libraries.
    • Allows DOM to interop with cancellation libraries.
    • Allows ECMAScript to support cancellation without a specific primitive.
    • Similar to ECMAScript definition of an “Iterable”.
  • Specify “Cancellation Protocol” adoption in WHATWG
    • Minor change to AbortSignal to support “Cancellation Protocol”.
    • Minor change to adopt foreign cancellation signals internally as AbortSignals.

5 of 8

ECMAScript Semantics

  • Add @@cancelSignal built-in symbol.
  • Expose @@cancelSignal as ‘Symbol.cancelSignal’.
  • Specify a “Cancelable” as being any object with an @@cancelSignal method that returns a “CancelSignal” object.
  • Specify a “CancelSignal” as an ordinary object with the following members:
    • A ‘signaled’ property that indicates whether cancellation was requested.
    • A ‘subscribe’ method that subscribes a callback and returns a “CancelSubscription” object.
      • The callback is to be invoked when cancellation is requested.
  • Specify a “CancelSubscription” as an ordinary object with an ‘unsubscribe’ method used to remove the subscription.

6 of 8

WHATWG Semantics

  • Add a @@cancelSignal method to AbortSignal that adapts the AbortSignal into an ECMAScript “CancelSignal” object.
  • Add semantics to “adopt” a “Cancelable” as an AbortSignal.
  • Modify semantics for the “follow” steps of AbortSignal to “adopt” a foreign “Cancelable”.
  • Modify spec text where necessary to allow a “Cancelable” in places that explicitly accept an AbortSignal.

7 of 8

Next Steps

  • Draft ECMAScript specification text.
  • Draft WHATWG specification text.
  • Work towards Stage 2 consensus.
  • Consider proposals for:
    • Cancelable ‘Promise.prototype.then’ (as well as ‘catch’, ‘finally’).
    • Cancelable ‘import’ call.

8 of 8

Summary

  • Explainer:
  • Proposed Semantics:
  • Status:
    • Stage 1