DoOnce class
A utility class to ensure that a specific asynchronous task is executed only once for a given key.
Methods
| wait |
Waits for the task associated with the given key to complete, or starts the task if it hasn't been started yet. |
Method Details
waitFor(string, () => Promise<T>)
Waits for the task associated with the given key to complete, or starts the task if it hasn't been started yet.
function waitFor(key: string, fn: () => Promise<T>): Promise<T>
Parameters
- key
-
string
The unique key identifying the task.
- fn
-
() => Promise<T>
A function that returns a promise representing the task to execute.
Returns
Promise<T>
A promise that resolves to the result of the task.