Show HN: ConcurrentML-style first-class synchronous operations for JavaScript (github.com) 1 points by nirisix 3y ago ↗ HN
[–] nirisix 3y ago ↗ You can try the following code snippet on the https://playground.esm.sh/ if you're interested.```typescriptimport { 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();```
1 comment
[ 2.2 ms ] story [ 11.1 ms ] thread```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();
```