06:20
<ljharb>
the issue is great, it'll get fixed, thanks
13:22
<snek>
is there a clean way to un-using something
14:18
<Aki>
r/BrandNewSentence
14:47
<Michael Ficarra>
...delete? 🤷‍♂️
14:55
<Michael Ficarra>
@rbuckton make it work
14:56
<rbuckton>
un-using? That's what DisposableStack is for
14:58
<rbuckton>
{
  using resource = getResource();
} // always disposes resource

// vs.

{
  using stack = new DisposableStack();
  const resource = stack.use(getResource());
  stack.move(); // move resource out of `stack`
} // stack disposed but resource isn't
15:03
<rbuckton>

One of its uses is with class constructors, where you want the resources to be disposed if the constructor throws, but tracked with the class if everything succeeds:

class MyResource {
  #disposables;
  #resource1;
  #resource2;
  constructor(options) {
    using stack = new DisposableStack();
    this.#resource1 = stack.use(getResource1(options));
    this.#resource2 = stack.use(getResource2(options));
    // both succeeded
    this.#disposables = stack.move(); // move out of stack to store in #disposables
  } // stack is disposed

  [Symbol.dispose]() {
    this.#disposables.dispose();
  }
}
17:23
<bakkot>
honestly I don't hate delete working though
17:28
<Michael Ficarra>
I know right
18:38
<snek>
would be nice if you could move a single item i guess
18:39
<snek>
wrapper could do that i suppose