# sync-channel

> synchronous communication channel

Latest version **0.0.6** (published 2013-07-18) · BSD license · 0 weekly downloads

## Install

```sh
npm install sync-channel
pnpm add sync-channel
yarn add sync-channel
bun add sync-channel
```

## 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.6 |
| Published | 2013-07-18 |
| First published | 2013-07-03 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | snetz |
| Maintainers | snetz |
| Keywords | concurrent, channel, async |

## Links

- npm: https://www.npmjs.com/package/sync-channel
- npm.io page: https://npm.io/package/sync-channel

## Alternatives

- [@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
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 0.0.6 (latest) — 2013-07-18
- 0.0.5 — 2013-07-03
- 0.0.4 — 2013-07-03
- 0.0.3 — 2013-07-03
- 0.0.2 — 2013-07-03
- 0.0.1 — 2013-07-03
- 0.0.0 — 2013-07-03

## README

# SyncChannel

A SyncChannel is a readable/writable communication channel. 
Communication is synchronous, i.e. the callback of a write gets called only when it's value has been read.
Reading/writing from/to a SyncChannel can be aborted by calling the abort function returned by 
the read/write methods.

## Installation
```
$ npm install sync-channel
```

# Examples

## read/write

``` js
var SyncChannel = require('sync-channel');

var channel = new SyncChannel();

channel.read(function(value) {
	console.log('value read', value);
});

channel.write(123, function() {
	console.log('value written');
});
```

## Aborting a read/write operation

``` js
var SyncChannel = require('sync-channel');

var channel = new SyncChannel();

var abortRead = channel.read(function(value) {
	console.log('value read', value);
});

setTimeout(function() {
	abortRead();
	console.log('you are so slow!');
}, 500);

setTimeout(function() {
	channel.write(123, function() {
		console.log('value written');
	});
}, 1000);
```

## tryRead

``` js
var SyncChannel = require('sync-channel');
var channel = new SyncChannel();
var result = channel.tryRead();
if(result !== null) {
	console.log('value read', result.value);
} else {
	console.log('no writers');         
}
```

## tryWrite
``` js
var SyncChannel = require('sync-channel');
var channel = new SyncChannel();
var result = channel.tryWrite(123);
if(result === true) {
	console.log('value written');
} else {
	console.log('no readers');
}
```

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