electric-sql / pglite

Lightweight WASM Postgres with real-time, reactive bindings.
https://pglite.dev
Apache License 2.0
8.33k stars 164 forks source link

PGliteInterface should implement Disposable [Symbol.dispose] #101

Closed mlhaufe closed 2 months ago

mlhaufe commented 3 months ago

TypeScript as of v5.2 added support for the Stage 3 ECMAScript Explicit Resource Management feature:

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management

So instead of having to write:

const conn = new PGliteWorker(this._connString)

try {
    const result = await conn.query(...)
    // ...
    return parse(result)
} finally {
    // ...
    conn.close()
}

We can write:

using conn = new PGliteWorker(this._connString)

const result = await conn.query(...)
// ...
return parse(result)

I think it will be a nice usability win if PGliteInterface implements the Disposable interface

samwillis commented 2 months ago

Hey, yep this would be a great use for these new features.

I would happily except a PR implementing it 👍