Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding 'Symbol.tokenSpecies' and 'Symbol.tokenSourceSpecies' #14

Closed
rbuckton opened this issue Jul 24, 2017 · 1 comment
Closed

Comments

@rbuckton
Copy link
Collaborator

rbuckton commented Jul 24, 2017

There is a note in EXTENSIBILITY.md indicating that we could simplify extensibility for CancellationTokenSource and CancellationToken by defining species symbols that link to the constructors for the entangled types:

class CancellationTokenSource {
  #token;

  ...

  get token() {
    if (!#token) {
      const C = this.constructor[Symbol.tokenSpecies];
      #token = new C(this);
    }
    return #token;
  }

  static get [Symbol.tokenSpecies]() { return CancellationToken; }
}

class CancellationToken {
  static #none;
  static #canceled;

  ...

  static get none() {
    if (!#none) {
      const C = this[Symbol.tokenSourceSpecies];
      const source = new C();
      source.close(); // cannot be canceled
      #none = source.token;
    }
    return #none;
  }

  static get canceled() {
    if (!#canceled) {
      const C = this[Symbol.tokenSourceSpecies];
      const source = new C();
      source.cancel(); // already canceled
      #canceled = source.token;
    }
    return #canceled;
  }

  static get [Symbol.tokenSourceSpecies]() { return CancellationTokenSource; }
}
@rbuckton
Copy link
Collaborator Author

Closing this issue as the proposal no longer specifies cancellation behavior. See #22 for the current thinking regarding cancellation.

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

No branches or pull requests

1 participant