You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As an Node application developer I want to use explicit resource management (using keyword) So that I don't need to write clean-up code using try/finally blocks to ensure resources are closed after use
TypeScript 5.2 adds support for the using keyword, defined by the upcoming Explicit Resource Management ECMAScript feature. For closeable resources that are only used within a defined scope, this avoids the need for clean-up code (typically implemented using try/finally blocks to ensure it is called in the event of an error) to close resources. It provides similar capability to Java's try-with-resources, and (to some extent) Go's defer.
This feature proposes that all objects in the Node API with close() methods to perform resource clean-up are augmented to implement the Disposable type, and have a [Symbol.dispose] method that calls the existing close().
For example, the existing application code:
constevents=awaitnetwork.getChaincodeEvents(chaincodeName,{startBlock: BigInt(101)});try{forasync(consteventofevents){// Process event}}finally{events.close();}
Could be simplified to the following, with the close() automatically called when the events variable goes out of scope:
using events=awaitnetwork.getChaincodeEvents(chaincodeName,{startBlock: BigInt(101)});forasync(consteventofevents){// Process event}
Tasks:
Augment CloseableAsyncIterable
Chaincode events
Block events
Filtered block events
Block and private data events
Augment Gateway
Add new code examples to API documentation:
Network
Network#getChaincodeEvents
Network#getBlockEvents
Network#getFilteredBlockEvents
Network#getBlockAndPrivateDataEvents
ChaincodeEventsRequest#getEvents
BlockEventsRequest#getEvents
FilteredBlockEventsRequest#getEvents
BlockAndPrivateDataEventsRequest#getEvents
The following samples should also be updated once this capability is published:
As an Node application developer
I want to use explicit resource management (
using
keyword)So that I don't need to write clean-up code using try/finally blocks to ensure resources are closed after use
TypeScript 5.2 adds support for the using keyword, defined by the upcoming Explicit Resource Management ECMAScript feature. For closeable resources that are only used within a defined scope, this avoids the need for clean-up code (typically implemented using try/finally blocks to ensure it is called in the event of an error) to close resources. It provides similar capability to Java's try-with-resources, and (to some extent) Go's
defer
.This feature proposes that all objects in the Node API with
close()
methods to perform resource clean-up are augmented to implement the Disposable type, and have a[Symbol.dispose]
method that calls the existingclose()
.For example, the existing application code:
Could be simplified to the following, with the
close()
automatically called when theevents
variable goes out of scope:Tasks:
The following samples should also be updated once this capability is published:
The text was updated successfully, but these errors were encountered: