https://github.com/dhcmrlchtdj/sync-op
Concurrent ML style first-class synchronous operations for JavaScript
https://github.com/dhcmrlchtdj/sync-op
channel cml concurrent-ml
Last synced: 5 months ago
JSON representation
Concurrent ML style first-class synchronous operations for JavaScript
- Host: GitHub
- URL: https://github.com/dhcmrlchtdj/sync-op
- Owner: dhcmrlchtdj
- License: lgpl-2.1
- Created: 2023-01-29T12:44:45.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-06-11T12:14:48.000Z (about 1 year ago)
- Last Synced: 2025-11-27T11:05:00.211Z (7 months ago)
- Topics: channel, cml, concurrent-ml
- Language: TypeScript
- Homepage:
- Size: 542 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sync-op
[](https://www.npmjs.com/package/sync-op)
Concurrent ML style first-class synchronous operations for JavaScript.
## Installation
Install the package using npm:
```sh
$ npm install sync-op
```
Or explore and experiment directly in your browser with [StackBlitz](https://stackblitz.com/edit/sync-op?file=index.ts).
## Usage
Below is a quick example to get you started:
```typescript
import { Channel, choose } from "sync-op"
const c1 = new Channel()
const c2 = new Channel()
const c3 = new Channel()
c1.send("hello").sync()
c2.send(1).sync()
c3.receive().sync()
const op = choose(c1.receive(), c2.receive()) // Op | Option>
await op.sync().unwrap() // maybe "hello" or 1
// `choose` can be nested
await choose(op, c3.send(true)).sync() // Option | Option | boolean
```
Dive into the [documentation](https://github.com/dhcmrlchtdj/sync-op/tree/main/doc) for the full API reference.
## Resource
- https://people.cs.uchicago.edu/~jhr/papers/cml.html
- http://cml.cs.uchicago.edu/pages/cml.html
- https://docs.racket-lang.org/reference/sync.html
- https://ocaml.org/api/Event.html
- https://wingolog.org/archives/2017/06/29/a-new-concurrent-ml
- https://medium.com/@asolove/synchronizable-abstractions-for-understandable-concurrency-64ae57cd61d1
- https://github.com/python-trio/trio/issues/242
## License
This library is licensed under LGPL-2.1.
The core of this library is derived from OCaml [event](https://github.com/ocaml/ocaml/blob/5.0.0/otherlibs/systhreads/event.ml).