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

0.8.0 • Public • Published

sync-op

npm version

Concurrent ML style first-class synchronous operations for JavaScript.

Installation

Install the package using npm:

$ npm install sync-op

Or explore and experiment directly in your browser with StackBlitz.

Usage

Below is a quick example to get you started:

import { Channel, choose } from "sync-op"

const c1 = new Channel<string>()
const c2 = new Channel<number>()
const c3 = new Channel<boolean>()

c1.send("hello").sync()
c2.send(1).sync()
c3.receive().sync()

const op = choose(c1.receive(), c2.receive()) // Op<Option<string> | Option<number>>
await op.sync().unwrap() // maybe "hello" or 1

// `choose` can be nested
await choose(op, c3.send(true)).sync() // Option<string> | Option<number> | boolean

Dive into the documentation for the full API reference.

Resource

License

This library is licensed under LGPL-2.1.

The core of this library is derived from OCaml event.

Package Sidebar

Install

npm i sync-op

Weekly Downloads

6

Version

0.8.0

License

LGPL-2.1

Unpacked Size

56.1 kB

Total Files

19

Last publish

Collaborators

  • dhcmrlchtdj