UNPKG

medium

Version:

CSP-style channel library using ES7 async/await keywords

28 lines (18 loc) 618 B
const { go, chan, take, put, sleep, buffers } = require('../lib/index') const ch = chan(buffers.dropping(2)) go(async function() { await sleep(1000) console.log('waited a second') console.log('this should be a 1:', await take(ch)) console.log('this should be a 2:', await take(ch)) await take(ch) console.log('this will just be queued, because the three was dropped and there are no pending puts') }) go(async function() { await put(ch, 1) await put(ch, 2) console.log('buffer full...') console.log('this 3 gets dropped') await put(ch, 3) console.log('and is released immediately') })