@fibjs/sync
Synchronize all kinds of async look like function to real non-blocking sync function, make the world peace and quiet!
Last updated 6 months ago by ngot .
MIT · Repository · Bugs · Original npm · Tarball
$ cnpm install @fibjs/sync 
SYNC missed versions from official npm registry.

@fibjs/sync

NPM version build status appveyor build status Test coverage David deps Known Vulnerabilities npm download

Synchronize all kinds of async look like function to original non-blocking sync one, make the world peace and quiet!

Install

$ npm i @fibjs/sync --save

Usage

const sync = require('@fibjs/sync');

function cb(callback) {
  callback(null, 'this is callback');
}

function pr() {
  return new Promise((resovle, reject) => {
    resovle('this is promise');
  });
}

function* ge() {
  return 'this is generator';
}

async function aa() {
  return 'this is async function';
}

// sync default to callback hanlder
const callbackSync = sync(cb);

try {
  const result = callbackSync();
} catch(e) {
  // handle the error
}

// the other apis
const newCb = sync.cb(cb);// callback
const newPr = sync.pr(pr);// promise
const newGe = sync.ge(ge);// generator
const newAa = sync.aa(aa);// async function

Now you can use newCb,newPr,newGe,newAa as a normal sync function and use try/catch to handle the error.

Questions & Suggestions

Please open an issue here.

License

MIT

Maintainers (2)
Downloads
Today 0
This Week 0
This Month 4
Last Day 0
Last Week 4
Last Month 21
Dependencies (1)
  • co ^4.6.0
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |