All Projects → jfet97 → Csp

jfet97 / Csp

Licence: mit
Communicating Sequential Processes in JavaScript

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Csp

Async Sema
Semaphore using `async` and `await`
Stars: ✭ 326 (+887.88%)
Mutual labels:  async, asynchronous, await
Swiftcoroutine
Swift coroutines for iOS, macOS and Linux.
Stars: ✭ 690 (+1990.91%)
Mutual labels:  async, asynchronous, await
Blockly Gamepad
A Blockly extension designed to develop games (made with love ❤)
Stars: ✭ 18 (-45.45%)
Mutual labels:  async, asynchronous, await
Coerce Rs
Coerce - an asynchronous (async/await) Actor runtime and cluster framework for Rust
Stars: ✭ 231 (+600%)
Mutual labels:  async, asynchronous, await
G3log
G3log is an asynchronous, "crash safe", logger that is easy to use with default logging sinks or you can add your own. G3log is made with plain C++14 (C++11 support up to release 1.3.2) with no external libraries (except gtest used for unit tests). G3log is made to be cross-platform, currently running on OSX, Windows and several Linux distros. See Readme below for details of usage.
Stars: ✭ 677 (+1951.52%)
Mutual labels:  async, asynchronous
Koahub Demo
koahub+async/await+mysql
Stars: ✭ 15 (-54.55%)
Mutual labels:  async, await
Modern Async
A modern JavaScript tooling library for asynchronous operations using async/await and promises
Stars: ✭ 31 (-6.06%)
Mutual labels:  async, await
Asyncawaitbestpractices
Extensions for System.Threading.Tasks.Task and System.Threading.Tasks.ValueTask
Stars: ✭ 693 (+2000%)
Mutual labels:  async, await
Awaitkit
The ES8 Async/Await control flow for Swift
Stars: ✭ 709 (+2048.48%)
Mutual labels:  async, await
Wx Promise Pro
✨强大、优雅的微信小程序异步库🚀
Stars: ✭ 762 (+2209.09%)
Mutual labels:  async, await
Ws Promise Client
PROJECT MOVED: https://github.com/kdex/ws-promise
Stars: ✭ 6 (-81.82%)
Mutual labels:  async, await
Vue Loadable
⏳ Improve your loading state control with pretty simple methods and helpers.
Stars: ✭ 23 (-30.3%)
Mutual labels:  async, asynchronous
Reservoir
Android library to easily serialize and cache your objects to disk using key/value pairs.
Stars: ✭ 674 (+1942.42%)
Mutual labels:  async, asynchronous
P Map
Map over promises concurrently
Stars: ✭ 639 (+1836.36%)
Mutual labels:  async, await
Request.swift
A tiny HTTP client written in swift. URLSession alternative
Stars: ✭ 14 (-57.58%)
Mutual labels:  async, asynchronous
Micro Router
🚉 A tiny and functional router for Zeit's Micro
Stars: ✭ 621 (+1781.82%)
Mutual labels:  async, await
Tornado Celery
Non-blocking Celery client for Tornado
Stars: ✭ 561 (+1600%)
Mutual labels:  async, asynchronous
Iguazu Rest
✨ Iguazu REST is a plugin for the Iguazu ecosystem that allows for pre-built async calls for REST with smart caching.
Stars: ✭ 21 (-36.36%)
Mutual labels:  async, asynchronous
Quill
Asynchronous Low Latency C++ Logging Library
Stars: ✭ 422 (+1178.79%)
Mutual labels:  async, asynchronous
Zsh Async
Because your terminal should be able to perform tasks asynchronously without external tools!
Stars: ✭ 528 (+1500%)
Mutual labels:  async, asynchronous

@jfet97/csp

A library for Communicating Sequential Processes, built on top of async/await and the asynchronous iterable interface.

npm version

Installation

This library requires async/await and for-await-of support.

$ npm install --save @jfet97/csp

Docs

You can find the documentation here.

Example Usage

Below is a trivial example of usage, that plays on the standard ping-pong example.

const { Channel } = require('@jfet97/csp');

const timeout = ms => new Promise(resolve => setTimeout(resolve, ms));

const wiff = new Channel();
const waff = new Channel();

const createBall = () => ({ hits: 0, status: '' });

const createBat = async (inbound, outbound) => {
  while (true) {
    const ball = await inbound.take(); // wait for an incoming ball
    ball.hits++;
    ball.status = ball.status === 'wiff!' ? 'waff!' : 'wiff!';
    console.log(`🎾  Ball hit ${ball.hits} time(s), ${ball.status}`);
    await timeout(500); // assume it's going to take a bit to hit the ball
    await outbound.put(ball); // smash the ball back
  }
};

createBat(waff, wiff); // create a bat that will wiff waffs
createBat(wiff, waff); // create a bat that will waff wiffs

waff.put(createBall());

ping pong

Async Iteration Protocol

Channels implement the async iterable interface, so you can transform the following illustrative code:

async function process (inbound, outbound) {
  while (true) {
    const msg = await inbound.take();
    // do stuff with msg
    await outbound.put(res);
  }
};

into a cleaner version, thanks to the powerful for-await-of:

async function process (inbound, outbound) {
  for await(const msg of inbound) {
    // do stuff with msg
    await outbound.put(res);
  }
};

Credits

Thanks to Joe Harlow for his work on this topic. If you are unfamiliar with CSP, I encourage you to see his talk where he describe a simpler version of this library as well.

Contributions

Contributions are welcomed and appreciated!

  1. Fork this repository.
  2. Make your changes, documenting your new code with comments.
  3. Submit a pull request with a sane commit message.

Feel free to get in touch if you have any questions.

License

Please see the LICENSE file for more information.

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].