Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fisker/promise-synchronizer
synchronize promise
https://github.com/fisker/promise-synchronizer
Last synced: 5 days 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 (about 8 years ago)
- Default Branch: main
- Last Pushed: 2024-05-22T20:12:14.000Z (6 months ago)
- Last Synced: 2024-05-22T21:36:14.805Z (6 months 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
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![npm](https://img.shields.io/npm/v/promise-synchronizer.svg?style=flat-square)](https://www.npmjs.com/package/promise-synchronizer)
[![npm](https://img.shields.io/npm/dt/promise-synchronizer.svg?style=flat-square)](https://www.npmjs.com/package/promise-synchronizer)
[![npm](https://img.shields.io/npm/dm/promise-synchronizer.svg?style=flat-square)](https://www.npmjs.com/package/promise-synchronizer)[![Build Status](https://img.shields.io/travis/fisker/promise-synchronizer.svg?style=flat-square)](https://travis-ci.org/fisker/promise-synchronizer)
[![Code Coverage](https://img.shields.io/coveralls/github/fisker/promise-synchronizer.svg?style=flat-square)](https://coveralls.io/github/fisker/promise-synchronizer)
[![MIT License](https://img.shields.io/npm/l/promise-synchronizer.svg?style=flat-square)](https://github.com/fisker/promise-synchronizer/blob/master/license)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](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
}
```