loatheb / syncify

make asynchronous function synchronously in node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SYNCIFY-test

convert Asynchronous function to Synchronous in node.

USAGE

  • some async function
function sleep(time) {
  return new Promise(resolve => setTimeout(resolve, time * 1000));
}
  • how we use it before
sleep(10)
  .then(doSomeThingWhenYouWakeUp);

(async function() {
  await sleep(10);
  await doSomeThingWhenYouWakeUp();
}());
  • how we use it after syncify
const syncify = require('syncify');

const sleepSync = syncify(sleep);
const doSomeThingWhenYouWakeUpSync = syncify(doSomeThingWhenYouWakeUp);

sleepSync(10);
doSomeThingWhenYouWakeUpSync();

LICENSE

MIT

About

make asynchronous function synchronously in node.js

License:MIT License


Languages

Language:JavaScript 100.0%