All Projects → NodeGuy → channel

NodeGuy / channel

Licence: Apache-2.0 License
Go-like channels for JavaScript

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to channel

Hunch
Hunch provides functions like: All, First, Retry, Waterfall etc., that makes asynchronous flow control more intuitive.
Stars: ✭ 94 (+91.84%)
Mutual labels:  channel, concurrency
gbp
Golang Best Practices (GBP™)
Stars: ✭ 25 (-48.98%)
Mutual labels:  channel, concurrency
TAOMP
《多处理器编程的艺术》一书中的示例代码实现,带有注释与单元测试
Stars: ✭ 39 (-20.41%)
Mutual labels:  concurrency
CacheLib
Pluggable in-process caching engine to build and scale high performance services
Stars: ✭ 637 (+1200%)
Mutual labels:  concurrency
pyphysim
Simulation of Digital Communication (physical layer) in Python.
Stars: ✭ 78 (+59.18%)
Mutual labels:  channel
atomix
Simple and easy wrappers for Go sync/atomic package.
Stars: ✭ 26 (-46.94%)
Mutual labels:  concurrency
transit
Massively real-time city transit streaming application
Stars: ✭ 20 (-59.18%)
Mutual labels:  concurrency
benchmark-http
No description or website provided.
Stars: ✭ 15 (-69.39%)
Mutual labels:  concurrency
multilayer-perceptron
Library to make and train a concurrent multilayer perceptron
Stars: ✭ 46 (-6.12%)
Mutual labels:  concurrency
futex
File-based Ruby Mutex
Stars: ✭ 14 (-71.43%)
Mutual labels:  concurrency
soabase-stages
A tiny library that makes staged/pipelined CompletableFutures much easier to create and manage
Stars: ✭ 23 (-53.06%)
Mutual labels:  concurrency
Shift
Light-weight EventKit wrapper.
Stars: ✭ 31 (-36.73%)
Mutual labels:  concurrency
traffic
Massively real-time traffic streaming application
Stars: ✭ 25 (-48.98%)
Mutual labels:  concurrency
Async-Channel
Python async multi-task communication library. Used by OctoBot project.
Stars: ✭ 13 (-73.47%)
Mutual labels:  concurrency
treap
A thread-safe, persistent Treap (tree + heap) for ordered key-value mapping and priority sorting.
Stars: ✭ 23 (-53.06%)
Mutual labels:  concurrency
nativescript-http
The best way to do HTTP requests in NativeScript, a drop-in replacement for the core HTTP with important improvements and additions like proper connection pooling, form data support and certificate pinning
Stars: ✭ 32 (-34.69%)
Mutual labels:  concurrency
pygolang
Go-like features for Python and Cython. (mirror of https://lab.nexedi.com/kirr/pygolang)
Stars: ✭ 37 (-24.49%)
Mutual labels:  concurrency
sto
Software Transactional Objects
Stars: ✭ 40 (-18.37%)
Mutual labels:  concurrency
aiorwlock
Read/Write Lock - synchronization primitive for asyncio
Stars: ✭ 90 (+83.67%)
Mutual labels:  concurrency
queueable
Convert streams to async ⌛ iterables ➰
Stars: ✭ 43 (-12.24%)
Mutual labels:  concurrency

Introduction

This is an idiomatic, minimally-opinionated Channel type for JavaScript that's inspired by Go's channels. It works in browsers and in Node.js. If you know how to use an Array then you already know most of how to use a Channel.

Why

Go's use of channels for concurrency is amazing and with JavaScript's async/await feature we have the basis for it as well. All that's missing is a solid Channel type. There are existing libraries but I wanted an idiomatic Channel type that's simple and minimally-opinionated.

This document assumes you're familiar with Go's channels and why you'd want to use them. For explanatory background, see my blog article on the subject.

Installation

$ npm install @nodeguy/channel

Basic Use

Create a channel with Channel().

To send a value to a channel use push. To receive a value from a channel use shift. Always precede the method calls with await. Close the channel when there are no more values to push.

const assert = require(`assert`);
const Channel = require(`@nodeguy/channel`);

const channel = Channel();

const send = async () => {
  await channel.push(42);
  await channel.close();
};

const receive = async () => {
  assert.equal(await channel.shift(), 42);
  assert.equal(await channel.shift(), undefined);
};

await Promise.all([send(), receive()]);

The push and shift methods are usually called in different async functions. They represent the two different ends of the channel and act to synchronize the behavior of the async functions.

API

The API is in the API.md file.

Similar Projects

Copyright

Copyright 2017 David Braun

Licensed under the Apache License, Version 2.0 (the "License"); you may not use these files except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].