medium
Version:
CSP-style channel library using ES7 async/await keywords
26 lines (14 loc) • 357 B
JavaScript
const { go, chan, take, put, sleep } = require('../lib/index')
const ch = chan(2)
go(async function() {
await sleep(1000)
// this take() will create room for the 3
await take(ch)
})
go(async function() {
await put(ch, 1)
await put(ch, 2)
console.log('buffer full...')
await put(ch, 3)
console.log('finally, 3 added to buffer')
})