UNPKG

375 BJavaScriptView Raw
1
2import channels from '../lib/index'
3
4var { go, chan, take, put, sleep } = channels
5
6var ch = chan(2)
7
8go(async function() {
9
10 await sleep(1000)
11
12 // this take() will create room for the 3
13 await take(ch)
14})
15
16go(async function() {
17
18 await put(ch, 1)
19 await put(ch, 2)
20
21 console.log('buffer full...')
22
23 await put(ch, 3)
24
25 console.log('finally, 3 added to buffer')
26})
27