UNPKG

medium

Version:

CSP-style channel library using ES7 async/await keywords

29 lines (23 loc) 575 B
const { go, chan, buffers, take, put, repeatTake } = require('../lib/index') const clock = chan(buffers.throttled(1000)) go(async () => { await repeatTake(clock, async (payload, lastMsg) => { const msg = lastMsg === 'tick' ? 'tock' : 'tick' console.log(`The clock goes: '${msg}'`) return msg }, 'tock') }) go(async () => { await put(clock, 1) await put(clock, 1) await put(clock, 1) await put(clock, 1) await put(clock, 1) await put(clock, 1) put(clock, 1) put(clock, 1) put(clock, 1) put(clock, 1) put(clock, 1) put(clock, 1) })