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

feat: add deferred executor, support chaining #4

Merged
merged 10 commits into from Nov 24, 2022
Merged

Conversation

kettanaito
Copy link
Member

@kettanaito kettanaito commented Nov 23, 2022

BREAKING CHANGE: Deferred promises are now implemented via the deferred executor function. There are no changes to the existing public API.

Changes

  • Supports Promise chaining.
  • Adds createDeferredExecutor to use this library with any Promise.
  • Improves type annotations in regard to what the deferred promise expects as the input and what is the promise's output:
const p = new DeferredPromise<number>()
  .then(() => 'hello')

// The input must be "number".
p.resolve(5)

// the output is "string"
// (the result of the "then" chain)
await p // "hello"
  • Deprecated: Removes DeferredPromise.result. Access the result by awaiting the promise instead.
  • Deprecated: The resolved promise state is replaced by fulfilled, which is the correct promise state representation per specification.

Roadmap

  • Document the deferred executor with more detail and then mention it in the deferred promise class documentation. That's exactly their relationship.
  • Support promises returned from .then/.catch.

@kettanaito kettanaito changed the title feat: support Promise chaining feat: add deferred executor, support chaining Nov 23, 2022
@kettanaito kettanaito force-pushed the fix/multiple-await branch 2 times, most recently from fae98eb to 3fcc8ca Compare November 23, 2022 18:18
@kettanaito kettanaito merged commit 1fe382e into main Nov 24, 2022
@kettanaito kettanaito deleted the fix/multiple-await branch November 24, 2022 12:32
@kettanaito
Copy link
Member Author

Released: v2.0.0 🎉

This has been released in v2.0.0!

Make sure to always update to the latest version (npm i @open-draft/deferred-promise@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

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