MCPcopy Create free account
hub / github.com/clockwork-xyz/examples / waitForThreadExec

Function waitForThreadExec

spl_transfer/tests/utils.ts:12–34  ·  view source on GitHub ↗
(
  clockworkProvider: ClockworkProvider,
  thread: PublicKey,
  maxWait: number = 60
)

Source from the content-addressed store, hash-verified

10// helpers
11let lastThreadExec = BigInt(0);
12const waitForThreadExec = async (
13 clockworkProvider: ClockworkProvider,
14 thread: PublicKey,
15 maxWait: number = 60
16) => {
17 let i = 1;
18 while (true) {
19 const execContext = (await clockworkProvider.getThreadAccount(thread))
20 .execContext;
21 if (execContext) {
22 if (
23 lastThreadExec.toString() == "0" ||
24 execContext.lastExecAt > lastThreadExec
25 ) {
26 lastThreadExec = execContext.lastExecAt;
27 break;
28 }
29 }
30 if (i == maxWait) throw Error("Timeout");
31 i += 1;
32 await new Promise((r) => setTimeout(r, i * 1000));
33 }
34};
35
36export { keypairFromFile, waitForThreadExec };

Callers 1

main.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected