undici
undici copied to clipboard
feat: Add Symbol.dispose and Symbol.asyncDispose support to DispatcherBase
This PR implements the new ECMAScript Explicit Resource Management proposal by adding disposal functionality to the DispatcherBase class. The changes include:
- Added
[Symbol.asyncDispose]()method that asynchronously closes the dispatcher - Added
[Symbol.dispose]()method that synchronously closes the dispatcher - Both methods reuse the existing
close()functionality - The synchronous version uses the
noopfunction 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)
I think this is a good start. You should make sure tha the result of .compose() can be disposed.
Also, docs are missing.
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.
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.