6 ms·
For APIs which don't support this, you can still use `using` by using DisposableStack: using disposer = new DisposableStack; const resource = disposer.
by bakkoting 1y ago
For APIs which don't support this, you can still use `using` by using DisposableStack:
using disposer = new DisposableStack;
const resource = disposer.adopt(new Resource, r => r.close());
This is still simpler than try/catch, especially if you have multiple resources, so it can be adopted as soon as your runtime supports the new syntax, without needing to wait for existing resources to update.