-
Notifications
You must be signed in to change notification settings - Fork 3k
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 #8271 from Expensify/marcaaron-onReadyTask
- Loading branch information
Showing
4 changed files
with
32 additions
and
12 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,18 @@ | ||
/** | ||
* Helper method to create a task to track the "readiness" of something and defer any actions until after something is "ready". | ||
* | ||
* @example | ||
* | ||
* const [isSomethingReady, setIsReady] = createOnReadyTask(); | ||
* isSomethingReady().then(() => doIt()); | ||
* setIsReady(); // -> doIt() will now execute | ||
* | ||
* @returns {Array<Promise, Function>} | ||
*/ | ||
export default function createOnReadyTask() { | ||
let resolveIsReadyPromise; | ||
const isReadyPromise = (new Promise((resolve) => { | ||
resolveIsReadyPromise = resolve; | ||
})); | ||
return [() => isReadyPromise, resolveIsReadyPromise]; | ||
} |