v134 · javascript
Explicit resource management (sync)
This feature addresses a common pattern in software development regarding the lifetime and management of various resources (memory, I/O, etc.). This pattern generally includes the allocation of a resource and the ability to explicitly release critical resources.
concepts
-
using
using statement — deterministic resource disposal in JS, same syntax as the TC39 explicit-resource-management proposal.
-
DisposableStack
The factory-pattern motivating case: conditionally acquire several resources, get LIFO cleanup on return or throw — no try/finally pyramid.
-
SuppressedError
When body and disposer both throw, classic try/finally loses one. SuppressedError preserves the chain — run four scenarios and walk the linked errors.
-
Resource Leak Detector
Run the same scenario with manual try/finally vs using and compare leaked vs cleaned resources side-by-side. Four failure modes show where try/finally drops resources that using still closes.
-
Connection pool
A 6-slot connection pool where
using conn = pool.checkout()auto-returns the connection when the block exits — even on throw. A live pool visualiser shows checked-out vs free slots. Run single queries, 4 concurrent requests, and a mid-query throw to see the pool always recover cleanly.
why it shipped
This feature addresses a common pattern in software development regarding the lifetime and management of various resources (memory, I/O, etc.). This pattern generally includes the allocation of a resource and the ability to explicitly release critical resources.