Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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!