Adding Go's defer to the TypeScript Compiler
3 points by nemin
3 points by nemin
If I'm not missing anything, we already have the using statement that does the same job.
Yeah, the article points this out at the end. They are semantically slightly different: defer declares functions that must run at cleanup, while using is more "provide me with a variable and ensure you call its dispose method when it goes out of scope".
We don't just have using, we have DisposableStack:
using stack = new DisposableStack();
await sema.acquire();
stack.defer(() => sema.release());
Or more tightly:
stack.adopt(await sema.acquire(), () => sema.release());
Real nice language experiment. Love these!
Are you hacking the old TS based compiler or the new Go one?