1 |
|
2 | import channels from '../lib/index'
|
3 |
|
4 | var { go, chan, take, put, sleep, buffers } = channels
|
5 |
|
6 | var ch = chan(buffers.dropping(2))
|
7 |
|
8 | go(async function() {
|
9 | await sleep(1000)
|
10 | console.log('waited a second')
|
11 | console.log('this should be a 1:', await take(ch))
|
12 | console.log('this should be a 2:', await take(ch))
|
13 | await take(ch)
|
14 | console.log('this will just be queued, because the three was dropped and there are no pending puts')
|
15 |
|
16 | })
|
17 |
|
18 | go(async function() {
|
19 |
|
20 | await put(ch, 1)
|
21 | await put(ch, 2)
|
22 |
|
23 | console.log('buffer full...')
|
24 |
|
25 | console.log('this 3 gets dropped')
|
26 | await put(ch, 3)
|
27 | console.log('and is released immediately')
|
28 |
|
29 | })
|