https://github.com/fisker/promise-synchronizer
synchronize promise
https://github.com/fisker/promise-synchronizer
Last synced: 6 months ago
JSON representation
synchronize promise
- Host: GitHub
- URL: https://github.com/fisker/promise-synchronizer
- Owner: fisker
- License: mit
- Created: 2016-09-26T16:51:45.000Z (almost 9 years ago)
- Default Branch: main
- Last Pushed: 2024-05-22T20:12:14.000Z (about 1 year ago)
- Last Synced: 2024-05-22T21:36:14.805Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 1.06 MB
- Stars: 8
- Watchers: 3
- Forks: 1
- Open Issues: 52
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# promise-synchronizer
[](https://github.com/prettier/prettier)
[](https://www.npmjs.com/package/promise-synchronizer)
[](https://www.npmjs.com/package/promise-synchronizer)
[](https://www.npmjs.com/package/promise-synchronizer)[](https://travis-ci.org/fisker/promise-synchronizer)
[](https://coveralls.io/github/fisker/promise-synchronizer)
[](https://github.com/fisker/promise-synchronizer/blob/master/license)
[](http://makeapullrequest.com)> synchronize promise
## Install
```bash
yarn add promise-synchronizer
```## Usage
### Wrap async functions
```js
import sync from 'promise-synchronizer'const asyncFunction = async () => 'Fulfilled'
asyncFunction()
// -> Promise { 'Fulfilled' }
const syncFunction = sync(asyncFunction)
syncFunction()
// -> 'Fulfilled'
```### Wait for promises
```js
import sync from 'promise-synchronizer'const promiseWillFulfill = Promise.resolve('Fulfilled')
sync(promiseWillFulfill)
// -> Fulfilledconst promiseWillReject = Promise.reject(new Error('Rejected'))
sync(promiseWillReject)
// -> Uncaught Error: Reject
```Use `try-catch`
```js
import sync from 'promise-synchronizer'try {
console.log(sync(promise)) // Fulfilled
} catch (error) {
console.error(error) // Rejected
}
```