Skip to content

📝 Add Library Integration guide for Promise-based API pattern#1133

Open
taras wants to merge 1 commit intov4from
docs/library-integration-guide
Open

📝 Add Library Integration guide for Promise-based API pattern#1133
taras wants to merge 1 commit intov4from
docs/library-integration-guide

Conversation

@taras
Copy link
Member

@taras taras commented Mar 1, 2026

Motivation

A community member asked in Discord: "Do you have any recommendations for using Effection inside a library, while exposing a more traditional API to the clients?"

This is a common use case that deserves dedicated documentation. The pattern evolved through discussion and is now captured in a gist, but should live in the official docs.

Approach

Add a new "Library Integration" guide to the Advanced section covering the pattern for using Effection internally while exposing a Promise-based API:

  • createScope() as the integration point
  • withResolvers() to synchronize initialization and prevent race conditions
  • resource() for lifecycle management
  • suspend() to keep the scope alive between calls
  • scope.run() as the bridge to Promises
  • Symbol.asyncDispose for await using support

Changes:

  • Create docs/library-integration.mdx with the full pattern and connection pool example
  • Add to "Advanced" section in docs/structure.json
  • Add cross-reference from docs/scope.mdx (in the "Creating a brand new Scope" section)
  • Add FAQ entry in docs/faq.mdx pointing to the guide

The guide includes gotchas identified during review:

  • Guarding against post-shutdown calls (track a closed flag)
  • Awaiting destroy() for cleanup completion
  • In-flight work behavior during shutdown
  • Startup failure propagation

@taras taras force-pushed the docs/library-integration-guide branch from 82e6674 to d68edcc Compare March 1, 2026 20:52
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 1, 2026

Open in StackBlitz

npm i https://pkg.pr.new/effection@1133

commit: 3cbf556

Add documentation for using Effection inside a library while exposing
a traditional Promise-based API to clients. The pattern uses createScope(),
withResolvers(), resource(), and suspend() to bridge between Effection's
structured concurrency and async/await.

- Create docs/library-integration.mdx with full pattern and example
- Add to Advanced section in structure.json
- Add cross-reference from scope.mdx
- Add FAQ entry pointing to the guide
@taras taras force-pushed the docs/library-integration-guide branch from d68edcc to 6fd23cf Compare March 1, 2026 20:59
Comment on lines +76 to +78
if (closed) {
throw new Error("Pool is shut down");
}
Copy link
Member

Choose a reason for hiding this comment

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

Code like this should never appear inside an Operation since this is the point of structured concurrency. The lifetime of code does not need to be track apart from its own execution. If this check is necessary, it should happen at the promise layer.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants