undici icon indicating copy to clipboard operation
undici copied to clipboard

feat: Add Symbol.dispose and Symbol.asyncDispose support to DispatcherBase

Open PandaWorker opened this issue 6 months ago • 3 comments

This PR implements the new ECMAScript Explicit Resource Management proposal by adding disposal functionality to the DispatcherBase class. The changes include:

  1. Added [Symbol.asyncDispose]() method that asynchronously closes the dispatcher
  2. Added [Symbol.dispose]() method that synchronously closes the dispatcher
  3. Both methods reuse the existing close() functionality
  4. The synchronous version uses the noop function as a callback

These changes enable modern resource management patterns:

// Synchronous disposal
using dispatcher = new Agent();

// Async disposal
await using asyncDispatcher = new Client();

The implementation follows the TC39 proposal currently in Stage 3 (https://github.com/tc39/proposal-explicit-resource-management)

PandaWorker avatar Jun 02 '25 15:06 PandaWorker

I think this is a good start. You should make sure tha the result of .compose() can be disposed.

Also, docs are missing.

mcollina avatar Jun 03 '25 07:06 mcollina

I'm also confused about what 's after .the close() agent no longer accepts requests, I think we need to completely not accept requests only at .destroy(), or add a method .closeIdleConnections(), which will simply wait for requests to complete and close all connections.

PandaWorker avatar Jun 03 '25 10:06 PandaWorker

I'm also confused about what 's after .the close() agent no longer accepts requests

I agree, I think it should error at this point but not drop any current requests.

mcollina avatar Jun 03 '25 13:06 mcollina