Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolving feature issue #886
using
is really neat and would be easily introduced. The only tricky part is to introduce it so that both the type system and the runtime adapts, compiles and runs no matter the typescript library versions.This would allow the following code:
...instead of the equivalent:
This PR does the following:
Q/A
Q: Why not Symbol.asyncDispose() ?
A: Would only be needed if release() was async and it's not. This PR only supports
using conn = sql.reserve()
, notawait using conn = sql.reserve()
because sql.release() returns void according to both typings and the runtime code.Q: How could it be tested?
A: Typescript will transpile
using
according to the target, so there's no need to use a modern javascript engine. Just make sure to use a modern version of typescript and ES library:"lib": ["ES2022"]
(or later)using conn = sql.reserve()
instead of having to try...finally...release().Q: Is this a typescript-only thing?
A: No, this is a TC39 stage 3 proposal, so it will soon be out in standard javascript. Until implemented in major JS engines, typescript or babel handles the transpilation. This PR does only declare the reserved sql instance to comply with this.
Q: Is the PR ready for release()
A: No, I thing the author @porsager need to review, build and test