Better HN
topnewbestaskshowjobs
Log inSign up

nirisix

4 karma · joined Aug 1, 2016 (10y ago) · 3 submissions

Submissions

comment 3y ago · link · parent

Disclaimer: I am the author of this library [1].

A few days ago, I ported ocaml/Event [2] to JavaScript, which provides concurrent ML-style synchronization operations.

It is possible to implement `Channel` and `select` in JS, but it is not easy to provide an idiomatic API and integrate it with the Promise ecosystem.

[1]: https://github.com/dhcmrlchtdj/sync-op [2]: https://ocaml.org/api/Event.html

comment 3y ago · link · parent

You can try the following code snippet on the https://playground.esm.sh/ if you're interested.

```typescript

import { Channel, select } from "https://esm.sh/sync-op";

async function main() {

const c1 = new Channel<string>();

const c2 = new Channel<number>();

const c3 = new Channel<boolean>();

c1.send("hello").sync();

c2.send(1).sync();

c3.send(true).sync();

const r1 = await select(c1.receive(), c2.receive(), c3.receive());

alert(r1.unwrap());

const r2 = await select(c1.receive(), c2.receive(), c3.receive());

alert(r2.unwrap());

}

main();

```

3.

Show HN: ConcurrentML-style first-class synchronous operations for JavaScript(github.com ↗)

1 points · by nirisix · 3y ago · 1 comment