# resync

> Yieldable node style callbacks

Latest version **0.9.1** (published 2015-08-02) · 0 weekly downloads

## Install

```sh
npm install resync
pnpm add resync
yarn add resync
bun add resync
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.1 |
| Published | 2015-08-02 |
| First published | 2015-03-13 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.11.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Maintainers | josiah |
| Keywords | resync, yeild, async |

## Links

- npm: https://www.npmjs.com/package/resync
- Repository: https://github.com/Josiah/resync
- Homepage: https://github.com/Josiah/resync#readme
- Issues: https://github.com/Josiah/resync/issues
- npm.io page: https://npm.io/package/resync

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 0.9.1 (latest) — 2015-08-02
- 0.9.0 — 2015-07-29
- 0.8.1 — 2015-05-27
- 0.8.0 — 2015-04-25
- 0.7.0 — 2015-04-19
- 0.6.0 — 2015-04-19
- 0.5.0 — 2015-04-19
- 0.4.0 — 2015-04-06
- 0.3.1 — 2015-04-04
- 0.3.0 — 2015-04-03
- 0.2.0 — 2015-04-03
- 0.1.0 — 2015-03-19
- 0.0.3 — 2015-03-19
- 0.0.2 — 2015-03-13
- 0.0.1 — 2015-03-13

## README

# Resync

[![Build Status](https://travis-ci.org/Josiah/resync.svg)](https://travis-ci.org/Josiah/resync)
[![Coverage Status](https://coveralls.io/repos/Josiah/resync/badge.svg)](https://coveralls.io/r/Josiah/resync)

## Features

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

## Usage

### Installation

Install this package using npm:

```sh
npm install --save resync
```

### Examples

#### Database query
```js
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
```js
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
```js
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
```js
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
});
```

---
_Source: https://npm.io/package/resync · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
