# syncopate

> Turn async to sync in JS

Latest version **0.0.4** (published 2014-10-13) · 0 weekly downloads

## Install

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

## 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.0.4 |
| Published | 2014-10-13 |
| First published | 2014-09-15 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Christian Blanquera |
| Maintainers | cblanquera |
| Keywords | async, sync |

## Links

- npm: https://www.npmjs.com/package/syncopate
- Repository: https://github.com/cblanquera/syncopate
- Issues: https://github.com/cblanquera/syncopate/issues
- npm.io page: https://npm.io/package/syncopate

## 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.0.4 (latest) — 2014-10-13
- 0.0.3 — 2014-10-08
- 0.0.2 — 2014-09-29
- 0.0.1 — 2014-09-15

## README

#Syncopate

  Turn async to sync in JS

### Installation

```bash
$ npm install syncopate
```

## Quick Start

```
var sync = require('syncopate');

var TestClass = function() {
	this.foo 	= 'bar';
	this.steps 	= [];
};

var test = new TestClass();

sync()
//sets the scope for this
.scope(test)
//step 1
.then(function(next) {
	setTimeout(function() {
		this.steps.push('step1');
		next(1);
	}.bind(this), 1);
//step 2
}).then(function(value, next) {
	setTimeout(function() {
		this.steps.push('step2');
		this.bar = value;
		next();
	}.bind(this), 1);
//step 3
}).then(function(next) {
	setTimeout(function() {
		this.steps.push('step3');
		console.log(this.bar); //--> 1
		console.log(this.foo); //--> 'bar'
		next();
	}.bind(this), 1);
//step 4
}).then(function(next) {
	setTimeout(function() {
		this.steps.push('step4');
		//enter the 'loop' thread
		next.thread('loop', 0);
	}.bind(this), 1);
//store a thread
}).thread('loop', function(i, next) {
	setTimeout(function() {
		if(i == 5) {
			next(23);
			return;
		}
		
		console.log(i < 5); //--> true
		next.thread('loop2', i + 10);
	}.bind(this), 1);
//store another thread
}).thread('loop2', function(i, next) {
	setTimeout(function() {
		console.log(i < 15); //--> true
		this.bar = 3;
		next.thread('loop', (i - 10) + 1);
	}.bind(this), 1);
//step 5
}).then(function(num, next) {
	setTimeout(function() {
		console.log(num); //--> 23
		console.log(test.bar); //--> 3
		console.log(test.steps[0]); //--> 'step1'
		console.log(test.steps[1]); //--> 'step2'
		console.log(test.steps[2]); //--> 'step3'
		console.log(test.steps[3]); //--> 'step4'
		next();
	}.bind(this), 1);
});

```

### Methods

  * scope(object) - Sets the scope for all then and thread callbacks
  * then(function) - Queues the next callback and calls it if nothing is queued
  * thread(string, function) - Stores a callback for later usage

### Why ?

  I realize there are other syncronize libraries like the ones from FutureJS which are more focused extensively on syncronous callbacks. 
  In practice, however I found myself calling nested sequence instances or the syntax just got too confusing for someone else to follow 
  despite my best efforts to keep it clean. While writing this code, for the past monthm I tried so many permutations that worked and 
  didn't work considering loops and dependancies, while keeping the code de-leveled and readable. This is the product of many starbucks 
  sessions.

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