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

Support for connection pools/ Missing AsyncResource #23

Closed
mcollina opened this issue Feb 1, 2023 · 3 comments
Closed

Support for connection pools/ Missing AsyncResource #23

mcollina opened this issue Feb 1, 2023 · 3 comments

Comments

@mcollina
Copy link

mcollina commented Feb 1, 2023

AsyncResource is a fundamental piece of the puzzle to support pools of sockets or similar. I don't see how this proposal handles that problem without it

@jridgewell
Copy link
Member

We expose the static AsyncContext.wrap() method, which allows you to capture the current global state for all AsyncContext instances:

const ctx = new AsyncContext();


const wrapped = ctx.run(1, () => {
  return AsyncContext.wrap((cb) => cb());
});

wrapped(() => {
  console.assert(ctx.get() === 1);
});

@legendecas
Copy link
Member

AsyncResource is equivalent to AsyncContext.wrap as they all capture the current async context global state. However, compared to AsyncResource, AsyncContext.wrap requires a function to be wrapped, as discussed at #21.

@mcollina
Copy link
Author

mcollina commented Feb 2, 2023

I'm closing this and will give feedback in #21.

@mcollina mcollina closed this as completed Feb 2, 2023
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

No branches or pull requests

3 participants