promise-synchronizer

3.0.0 • Public • Published

promise-synchronizer

styled with prettier npm npm npm

Build Status Code Coverage MIT License PRs Welcome

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
}

Package Sidebar

Install

npm i promise-synchronizer

Weekly Downloads

1,306

Version

3.0.0

License

MIT

Unpacked Size

7.48 kB

Total Files

5

Last publish

Collaborators

  • fisker