Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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