promise-synchronizer
v3.0.0
Published
synchronize promise
Downloads
6,741
Maintainers
Readme
promise-synchronizer
synchronize promise
Install
yarn add promise-synchronizer
Usage
Wrap async functions
import sync from 'promise-synchronizer'
const asyncFunction = async () => 'Fulfilled'
asyncFunction()
// -> Promise { 'Fulfilled' }
const syncFunction = sync(asyncFunction)
syncFunction()
// -> 'Fulfilled'
Wait for promises
import sync from 'promise-synchronizer'
const promiseWillFulfill = Promise.resolve('Fulfilled')
sync(promiseWillFulfill)
// -> Fulfilled
const promiseWillReject = Promise.reject(new Error('Rejected'))
sync(promiseWillReject)
// -> Uncaught Error: Reject
Use try-catch
import sync from 'promise-synchronizer'
try {
console.log(sync(promise)) // Fulfilled
} catch (error) {
console.error(error) // Rejected
}