# chan

> A go style channel implementation that works nicely with co

Latest version **0.6.1** (published 2014-08-05) · MIT license · 0 weekly downloads

## Install

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

## 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.6.1 |
| Published | 2014-08-05 |
| First published | 2013-11-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 111 |
| Author | Brent Burgoyne |
| Maintainers | brentburgoyne |
| Keywords | async, go, channel, co, generator |

## Links

- npm: https://www.npmjs.com/package/chan
- Repository: http://github.com/brentburgoyne/chan
- Homepage: https://github.com/brentburgoyne/chan
- Issues: https://github.com/brentburgoyne/chan/issues
- npm.io page: https://npm.io/package/chan

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 0.6.1 (latest) — 2014-08-05
- 0.6.0 — 2014-08-05
- 0.3.0 — 2014-01-07
- 0.2.0 — 2013-12-07
- 0.1.0 — 2013-12-02
- 0.0.0 — 2013-11-11

## README

# Chan

A [golang](http://golang.org) like channel implementation for JavaScript that
works well with [co](https://github.com/visionmedia/co).

[![Build Status](https://travis-ci.org/brentburgoyne/chan.png)](https://travis-ci.org/brentburgoyne/chan)
[![Code Climate](https://codeclimate.com/github/brentburgoyne/chan.png)](https://codeclimate.com/github/brentburgoyne/chan)
[![Dependency Status](https://gemnasium.com/brentburgoyne/chan.png)](https://gemnasium.com/brentburgoyne/chan)

## Features

- CSP Style channels in JavaScript
- Buffered or Unbuffered channels
- Channels can be closed
- API designed to work well with generators and co
- Can be used without generators
- Channels can be selected similar to Go's select statement

## Installation

```bash
$ npm install chan --save
```

## The Basics

Chan is inspired by golang's channels. It is implemented as a function that
represents an asynchronous first in first out queue.

```js
var makeChan = require('chan')
// make a new unbuffered channel
var ch = makeChan()
typeof ch // -> 'function'
```

### Sending values to the channel

Values are added to the
channel by calling the function with either `(value)` or `(error, value)`. The
return value is a thunk (a function that take a node-style callback as its only
argument). The callback given to the thunk is called once the value is added.

```js
ch('foo')(function (err) {
  if (err) {
    // There was an error putting the value on the channel
  } else {
    // The value was successfully put on the channel
  }
})
```

### Receiving values from the channel

Values are removed from the channel by calling it with a node-style callback as
this first argument. When a value is available on the channel the callback is
called with the value or error. In this case the channel itself can also be a
thunk.

```js
ch(function (err, val) {
  // called when there is a value or error on the channel
})
```

### Generators

Because thunks are yield-able in a co generator, chan works very well when
combined with co. Using them together makes chan feel very similar to go
channels.

```js
var co = require('co')

co(function *() {
  var val = yield ch
})

co(function *() {
  yield ch('foo')
})
```

## Buffer

Docs coming soon...

## Close

Docs coming soon...

## Select

Docs coming soon...

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