sigsel
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

sigsel.js

npm size deps

Selectable signals.

Inspired by Go's channels and Clojure's core.async, this library aims to make concurrent programming easier.

Since JS is single-threaded, there can be no data races across synchronous calls. This means we do not need channels and can just share variables. However, we still want a mechanism for synchronizing asynchronous operations. For that purpose, we use a signal object.

Installation

npm i sigsel

Usage

Counter

import { signal, select } from "sigsel";
 
(async () => {
  let counter = 0;
  const click = signal();
  const timeout = signal();
  for (;;) {
    const timer = setTimeout(timeout, 1000);
    render(<button onclick={click}>{counter}</button>);
    switch (await select(click, timeout)) {
      case click:
        counter++;
        break;
      case timeout:
        counter--;
        break;
    }
    clearTimeout(timer);
  }
})();

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.0
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 2.0.0
    1
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i sigsel

Weekly Downloads

0

Version

2.0.0

License

MIT

Unpacked Size

4.29 kB

Total Files

6

Last publish

Collaborators

  • rliang