[Symbol.dispose]() implementation added to Gateway and CloseableAsyncIterable. For environments that support ECMAScript resource management (such as TypeScript 5.2 and later), this allows the using keyword to be used to automatically close chaincode and block event iterables when they go out of scope instead of explcitly calling close with a try/finally block.
For example, this eventing code:
const events = await network.getChaincodeEvents(chaincodeName, { startBlock: BigInt(101) });
try {
for async (const event of events) {
// Process event
}
} finally {
events.close();
}
Can be replaced with the following, where the clean-up carried out by calling events.close() is done automatically when the events variable goes out of scope:
using events = await network.getChaincodeEvents(chaincodeName, { startBlock: BigInt(101) });
for async (const event of events) {
// Process event
}
[Symbol.dispose]()
implementation added to Gateway and CloseableAsyncIterable. For environments that support ECMAScript resource management (such as TypeScript 5.2 and later), this allows theusing
keyword to be used to automatically close chaincode and block event iterables when they go out of scope instead of explcitly calling close with a try/finally block.For example, this eventing code:
Can be replaced with the following, where the clean-up carried out by calling
events.close()
is done automatically when theevents
variable goes out of scope:Closes #636