Skip to content

Turn ES6 Promise into synchronize function call, a simple wrapper of deasync package

License

Notifications You must be signed in to change notification settings

Yukaii/synchronized-promise

Repository files navigation

synchronized-promise

All Contributors

npm version Build Status

Turn ES6 Promise into synchronize function call, a simple wrapper of deasync package

Installation

npm install synchronized-promise --save

Usage

First, you need to require the synchronized-promise package, for JavaScript:

const sp = require('synchronized-promise')

For TypeScript or ES6 later JavaScript:

import sp from 'synchronized-promise'

Then call it as the following example:

// 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 for usage in details.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


侠小然

💻

Clar Charron

💻

Pedro Augusto de Paula Barbosa

📖

This project follows the all-contributors specification. Contributions of any kind welcome!

About

Turn ES6 Promise into synchronize function call, a simple wrapper of deasync package

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published