Created
June 29, 2023 14:25
-
-
Save fiuzagr/6b71081f24ac74d4a07aee61e727d1cd to your computer and use it in GitHub Desktop.
Queue Promises
This file contains hidden or 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
let _queue: Promise<any> = Promise.resolve(true); | |
const queuePromise = (operation: (value: any) => Promise<any>) => { | |
return new Promise((resolve, reject) => { | |
_queue = _queue | |
.then(operation) | |
.then(resolve) | |
.catch(reject); | |
}); | |
}; | |
export default queuePromise; | |
// | |
// usage: | |
// queuePromise(() => promise1.then()).then(finishExecution) | |
// queuePromise((result1) => promise2.then()).then(finishExecution) | |
// queuePromise((result2) => promiseN.then()).then(finishExecution) | |
// | |
// finishExecution will be run one time. Can be declared in the any queue().then | |
// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment