UNPKG

554 BJavaScriptView Raw
1
2import channels from '../lib/index'
3
4var { go, chan, take, put, sleep, buffers } = channels
5
6var ch = chan(buffers.sliding(2))
7
8go(async function() {
9 await sleep(1000)
10 console.log('waited a second')
11 console.log('this should be a 2:', await take(ch))
12 console.log('this should be a 3:', await take(ch))
13})
14
15go(async function() {
16
17 await put(ch, 1)
18 await put(ch, 2)
19
20 console.log('buffer full...')
21
22 console.log('this 3 gets slid into the last spot, dropping the first (1)')
23 await put(ch, 3)
24 console.log('and is released immediately')
25
26})