We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using
withSession
This change simplifies session management by automatically handling cleanup with Symbol.asyncDispose https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management
Symbol.asyncDispose
Before
public async withSession<Return>(callback: (session: Session) => Return): Promise<Awaited<Return>> { let session: Session | undefined = undefined try { session = await this.store.session(this.profile).open() const result = await callback(session) return result } finally { if (session?.handle) { await session.close() } } }
After
public async getSession() { const session = await this.store.session(this.profile).open() return { session, [Symbol.asyncDispose]: async () => { if (session?.handle) { await session.close() } }, } }
And usage of the session will also be changed from Before
await agentContext.wallet.withSession((session) => session.insert({ category: record.type, name: record.id, value, tags }) )
await using session = await agentContext.wallet.getSession() await session.session.insert({ category: record.type, name: record.id, value, tags })
Some initial changes that are required to start using the using keyword are :
prettier
"lib": ["ESNext.Disposable"]
@TimoGlastra Do you think any more changes are required or this would be a good start ?
The text was updated successfully, but these errors were encountered:
No branches or pull requests
This change simplifies session management by automatically handling cleanup with
Symbol.asyncDispose
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-managementBefore
After
And usage of the session will also be changed from
Before
After
Some initial changes that are required to start using the
using
keyword are :prettier
to v3 and also dependent packages"lib": ["ESNext.Disposable"]
@TimoGlastra Do you think any more changes are required or this would be a good start ?
The text was updated successfully, but these errors were encountered: