-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Solve issue with function invocation.
- Loading branch information
Showing
4 changed files
with
78 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import crypto from 'crypto'; | ||
|
||
interface Invocation { | ||
resolve: (value: string) => void; | ||
reject: (reason: string) => void; | ||
} | ||
|
||
class InvokeQueue { | ||
private queue: Record<string, Invocation> = {}; | ||
|
||
public push(invoke: Invocation): string { | ||
const id = crypto.randomBytes(16).toString('hex'); | ||
this.queue[id] = invoke; | ||
return id; | ||
} | ||
|
||
public get(id: string): Invocation { | ||
const invoke = this.queue[id]; | ||
delete this.queue[id]; | ||
return invoke; | ||
} | ||
} | ||
|
||
export const invokeQueue = new InvokeQueue(); |
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