Created
June 23, 2020 23:19
-
-
Save shinchit/638dce462e75eb30abdab34d22b63a85 to your computer and use it in GitHub Desktop.
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
import Promise from 'bluebird'; | |
import { Mutex } from 'await-semaphore'; | |
const mutex = new Mutex(); | |
mutex.use(() => { | |
// write process you want to control exclusively | |
// example shows below | |
const promise = new Promise((resolve) => { | |
Promise.props({ // see. http://bluebirdjs.com/docs/api/promise.props.html | |
labels: this.getLabels(), // Slow and asynchronous process | |
feelings: this.getFeelingsData(), // Slow and asynchronous process | |
}) | |
.then((result) => { | |
this.labels.replace(result.labels); | |
this.feelingsData.replace(result.feelings); | |
resolve(true); | |
}) | |
.catch((e) => { | |
throw e; | |
}); | |
}); | |
return promise; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment