(no title)
mst | 9 months ago
const defer = f => ({ [Symbol.dispose]: f })
using defer(() => cleanup())
That only just occurred to me. To everybody else who finds it completely obvious, "well done" but it seemed worthy of mention nonetheless.
masklinn|9 months ago
This is notably necessary for scope-bridging and conditional registration as `using` is block-scoped so
But because `using` is a variant of `const` which requires an initialisation value which it registers immediately this will fail: and so will this: Instead, you'd write: Similarly if you want to acquire a resource in a block (conditionally or not) but want the cleanup to happen at the function level, you'd create a stack at the function toplevel then add your disposables or callbacks to it as you go.MrResearcher|9 months ago
mattlondon|9 months ago