Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yukaii/synchronized-promise
Turn ES6 Promise into synchronize function call, a simple wrapper of deasync package
https://github.com/yukaii/synchronized-promise
deasync promise synchronize
Last synced: 3 months ago
JSON representation
Turn ES6 Promise into synchronize function call, a simple wrapper of deasync package
- Host: GitHub
- URL: https://github.com/yukaii/synchronized-promise
- Owner: Yukaii
- License: mit
- Created: 2018-02-12T13:54:18.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-03T12:41:50.000Z (about 2 years ago)
- Last Synced: 2024-10-28T07:48:18.600Z (3 months ago)
- Topics: deasync, promise, synchronize
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/synchronized-promise
- Size: 580 KB
- Stars: 44
- Watchers: 4
- Forks: 5
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# synchronized-promise
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors)[![npm version](https://badge.fury.io/js/synchronized-promise.svg)](https://badge.fury.io/js/synchronized-promise)
[![Build Status](https://travis-ci.org/Yukaii/synchronized-promise.svg?branch=master)](https://travis-ci.org/Yukaii/synchronized-promise)Turn ES6 Promise into synchronize function call, a simple wrapper of deasync package
## Installation
```js
npm install synchronized-promise --save
```## Usage
First, you need to require the `synchronized-promise` package, for JavaScript:
```js
const sp = require('synchronized-promise')
```For TypeScript or ES6 later JavaScript:
```ts
import sp from 'synchronized-promise'
```Then call it as the following example:
```js
// An promise base async function
let asyncFunction = (value) => {
return new Promise((resolve, reject) => {
setTimeout(function () {
resolve(value)
}, 2000)
})
}// regular usage
asyncFunction(5).then(value => value === 5)// make it synchronized
let syncFunc = sp(asyncFunction)
const value = syncFunc(5) // value === 5
```See [`test.js`](https://github.com/Yukaii/synchronized-promise/blob/master/test.js) for usage in details.
## Contributors β¨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
δΎ ε°ηΆ
π»
Clar Charron
π»
Pedro Augusto de Paula Barbosa
π
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!