Repository navigation
feat: support Symbol.asyncDispose on client, session, and operation - #586
vuanhphung wants to merge 3 commits into
Conversation
DBSQLClient, DBSQLSession, and DBSQLOperation (and the IDBSQLClient, IDBSQLSession, and IOperation interfaces) gain [Symbol.asyncDispose](), which delegates to close(), so `await using` works on both backends. Disposing an already-closed object is a no-op. The published typings declare SymbolConstructor.asyncDispose themselves, so consumers don't need TypeScript's esnext.disposable lib or a recent @types/node. Fixes #331 Signed-off-by: Vu Anh Phung <vu.phung@databricks.com> Co-authored-by: Isaac <no-reply@databricks.com>
|
@bot Please mention adding esnext.disposable to compilerOptions.lib when the consumer’s typings don’t already provide disposable declarations. Otherwise, the documented example can fail even with TypeScript 5.2+. |
|
Thanks for your contribution! To satisfy the DCO policy in our contributing guide every commit message must include a sign-off message. One or more of your commits is missing this message. You can reword previous commit messages with an interactive rebase ( |
Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
|
Pushed Started from 82b6e7b. I added a note to the README's "Automatic cleanup with |
|
Thanks for your contribution! To satisfy the DCO policy in our contributing guide every commit message must include a sign-off message. One or more of your commits is missing this message. You can reword previous commit messages with an interactive rebase ( |
DBSQLClient,DBSQLSession, andDBSQLOperationnow implement[Symbol.asyncDispose](), so they work withawait using(TC39 explicit resource management). Disposal delegates toclose(): disposing an already-closed object is a no-op, and a real close failure still surfaces. The method is on the shared facades, so it covers both the Thrift and kernel backends. It's also declared onIDBSQLClient,IDBSQLSession, andIOperation, because those are the typesconnect(),openSession(), andexecuteStatement()return. Custom implementations of those interfaces will need to add the method; the CHANGELOG says so.Typings: the emitted
.d.tsreferenceSymbol.asyncDispose. TypeScript only declares it with theesnext.disposablelib, and@types/node18.11 and 20.3.0 don't declare it either. 20.3.0 is the version consumers get transitively throughapache-arrow. So the package ships the sameSymbolConstructor.asyncDispose: unique symboldeclaration that TypeScript and@types/nodeuse, and the declarations merge cleanly. At runtime the symbol exists on every supported Node line. Node 24+ runsawait usingnatively; Node 22 needs TypeScript 5.2+ to compile it.Verification:
npm test, lint, prettier, type-check, and build all pass.npm packtarballs ofmainand of this branch. It covers 1,232 configs: TypeScript 4.7–7.0 ×@types/node(transitive, 18.11, 20.3.0, 20.19, 22, 24, 26) × lib (default/es2022/esnext/esnext.disposable) ×skipLibCheckon/off × node10/node16. Each config runs with and without the@types/thrift/node-int64/node-fetchtypings thatskipLibCheck: falseneeds. No config gets new errors. All 681 configs that are clean onmainstay clean, including 89 withskipLibCheck: false(TS 4.7–7.0, with@types/node18.11 and 20.3.0 among them). Explicit[Symbol.asyncDispose]()calls type-check in all of those configs.await usingtype-checks in every eligible config (TS ≥ 5.2 with a disposable lib): 105 withskipLibCheckand 25 without.await usingcloses the operation, then the session, then the client on both backends. Tested on Node 24 (native and TS-downleveled) and Node 22.23.4 (downleveled). An error thrown inside the block propagates, and disposal still runs. Related e2e specs pass.Fixes #331
This pull request and its description were written by Isaac.