res

resync

Yieldable node style callbacks

Showing:

Popularity

Downloads/wk

1

GitHub Stars

4

Maintenance

Last Commit

6yrs ago

Contributors

0

Package

Dependencies

0

Size (min+gzip)

0.7KB

License

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Resync

Build Status Coverage Status

Features

  • Node callback management like synchronous code
  • Promise support for
    • Native ES6 promises
    • Bluebird

Usage

Installation

Install this package using npm:

npm install --save resync

Examples

Database query

var Resync = require('resync');
var Pg = require('postgres');

var loadProducts = Resync(function * (wait) {
  var pg = yield Pg.connect('postgres://username:password@localhost/database', wait());
  var client = pg[0];
  var release = pg[1];

  var result = yield client.query('SELECT * FROM product', wait());

  return result.rows;
});

loadProducts(function (err, products) {
  // Handle those errors & do something with your products
});

Multiple results

var Resync = require('resync');
var Redis = require('redis');

var loadCachedProducts = Resync(function * (ids, wait) {
  var redis = Redis.createClient();

  for (let id of ids) {
    redis.hgetall(`products:${id}`, wait());
  }

  return yield Array;
});

Passing parameters

var Resync = require('resync');
var Pg = require('postgres');

var loadProduct = Resync(function * (id, wait) {
  var pg = yield Pg.connect('postgres://username:password@localhost/database', wait());
  var client = pg[0];
  var release = pg[1];

  var result = yield client.query('SELECT * FROM product WHERE product = ?', [id], wait());

  return result.rows;
});

loadProduct(111, function (err, product) {
  // Handle those errors & do something with your product
});

Handling errors

var Resync = require('resync');
var Fs = require('fs');

var loadProduct = Resync(function * (directory, wait) {
  try {
    return yield Fs.readdir(directory, wait());
  } catch (err) {
    return [];
  }
});

loadProduct('/var/awesome/dir', function (err, files) {
  // Handle those errors or do something with your files
});

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial