fs icon indicating copy to clipboard operation
fs copied to clipboard

`FileSystemObserver` should support `Symbol.dispose`

Open mitranim opened this issue 5 months ago • 1 comments

What problem are you trying to solve?

Manual cleanup is easy to forget. try/finally requires nesting. Cleanup with using is more convenient.

What solutions exist today?

const obs = new FileSystemObserver(myCallback)
await obs.observe(handle)
try {/* Various activities. */}
finally {obs.disconnect()}

How would you solve it?

// This should be built-in.
const pro = FileSystemObserver.prototype
if (!pro[Symbol.dispose]) {
  const desc = Object.getOwnPropertyDescriptor(pro, `disconnect`)
  Object.defineProperty(pro, Symbol.dispose, desc)
}

using obs = new FileSystemObserver(myCallback)
await obs.observe(handle)
/* Various activities. */

mitranim avatar Aug 14 '25 15:08 mitranim

Blocked on https://github.com/whatwg/webidl/pull/1488 ?

saschanaz avatar Oct 23 '25 14:10 saschanaz