-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from tkiapril/feat/recover
Defensive measures
- Loading branch information
Showing
11 changed files
with
661 additions
and
419 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export type Awaitable<T> = T | PromiseLike<T>; | ||
|
||
export function createMutex() { | ||
const queue: bigint[] = []; | ||
let sourcesMutex = new AbortController(); | ||
sourcesMutex.abort(); | ||
return async function doMutex<T>(fn: () => Awaitable<T>) { | ||
const ticket = crypto.getRandomValues(new BigUint64Array(1))[0]; | ||
queue.push(ticket); | ||
do { | ||
await new Promise<void>((resolve) => { | ||
sourcesMutex.signal.addEventListener("abort", () => resolve()); | ||
if (sourcesMutex.signal.aborted) resolve(); | ||
}); | ||
} while (queue[0] !== ticket); | ||
sourcesMutex = new AbortController(); | ||
let result: T; | ||
try { | ||
result = await fn(); | ||
} finally { | ||
queue.shift(); | ||
sourcesMutex.abort(); | ||
} | ||
return result; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ services: | |
DATABASE_URL: postgres://postgres:V0uYcxk2dFixtPWfK4Nb@db/postgres | ||
AMQP_BROKER_URL: amqp://message-queue-broker | ||
CHAIN_DEFINITION_URL: https://esm.sh/@wagmi/[email protected]#goerli | ||
BLOCK_FINALITY: safe | ||
emitter: | ||
depends_on: | ||
message-queue-broker: | ||
|
@@ -26,7 +27,6 @@ services: | |
DATABASE_URL: postgres://postgres:V0uYcxk2dFixtPWfK4Nb@db/postgres | ||
AMQP_BROKER_URL: amqp://message-queue-broker | ||
CHAIN_DEFINITION_URL: https://esm.sh/@wagmi/[email protected]#goerli | ||
BLOCK_FINALITY: safe | ||
api: | ||
depends_on: | ||
message-queue-broker: | ||
|
Oops, something went wrong.