1.0.1 • Published 6 years ago
promise-decoupling v1.0.1
PROMISE-DECOUPLING
Simplify the use of Promise, to use async parallel functions need to wait for another function.
Example:
import promiseDecoupling from 'promise-decoupling'
const something = promiseDecoupling()
const successCode = async () => {
/*... your code ...*/
something.resolve()
}
const failCode = async () => {
/*... your code ...*/
something.reject()
}
const secondaryCode = async () => {
try {
/*... your code ...*/
successCode()
} catch (error) {
/*... your code ...*/
failCode()
}
}
const primaryCode = async () => {
/*... your code ...*/
await something.promise()
/*... your code ...*/
}
const main = () => {
primaryCode()
secondaryCode()
}