Skip to content

Commit

Permalink
use async, respecting the function decl itself
Browse files Browse the repository at this point in the history
  • Loading branch information
erhant committed Oct 6, 2024
1 parent 57b56b2 commit f8fa9eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ function cli(args: string[]) {
.addCommand(verify)
.addCommand(calldata)
// teardown to terminate SnarkJS, otherwise hangs the program
.hook('postAction', () => teardown())
.hook('postAction', async () => await teardown())
.parse(args);

// TODO: test graceful exits
Expand Down
13 changes: 10 additions & 3 deletions src/utils/teardown.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
declare global {
// eslint-disable-next-line no-var
var curve_bn128: {terminate: () => void} | undefined;
var curve_bn128: {terminate: () => Promise<void>} | undefined;
}

export function teardown() {
if (globalThis.curve_bn128) globalThis.curve_bn128.terminate();
/**
* Teardown function to be run for graceful exits.
*
* SnarkJS may attach curve_bn128 to global, but does not terminate it.
* We have to do it manually (see https://github.com/iden3/snarkjs/issues/152)
* For this, we use the [`terminate`](https://github.com/iden3/ffjavascript/blob/master/src/bn128.js#L48) function.
*/
export async function teardown() {
if (globalThis.curve_bn128) await globalThis.curve_bn128.terminate();
}

0 comments on commit f8fa9eb

Please sign in to comment.