Async RAII pattern: acquire a ref, await fn, auto-release.
fn
The service type.
The return type of fn.
The context to acquire from.
The service token.
Async function that receives the unwrapped service.
The return value of fn.
1.2.0
const balance = await withRefAsync(ctx, Tokens.RPC, async rpc => { return rpc.getBalance(pubkey);});// ref is auto-released after await Copy
const balance = await withRefAsync(ctx, Tokens.RPC, async rpc => { return rpc.getBalance(pubkey);});// ref is auto-released after await
Async RAII pattern: acquire a ref, await
fn, auto-release.