Skip to content

Commit

Permalink
chore: change state mgr to return in withTransaction (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleyyconsensys authored Oct 9, 2024
1 parent 52bf68f commit 40dad6e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/starknet-snap/src/utils/snap-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ export abstract class SnapStateManager<State> {
*
* @param callback - A Promise function that takes the state as an argument.
*/
public async withTransaction(
callback: (state: State) => Promise<void>,
): Promise<void> {
await this.mtx.runExclusive(async () => {
public async withTransaction<Response>(
callback: (state: State) => Promise<Response>,
): Promise<Response> {
return await this.mtx.runExclusive(async () => {
await this.#beginTransaction();

if (
Expand All @@ -88,8 +88,9 @@ export abstract class SnapStateManager<State> {
);

try {
await callback(this.#transaction.current);
const result = await callback(this.#transaction.current);
await this.set(this.#transaction.current);
return result;
} catch (error) {
logger.info(
`SnapStateManager.withTransaction [${
Expand Down

0 comments on commit 40dad6e

Please sign in to comment.