Sawtaytoes
3/17/2019 - 8:30 AM

CSP Example Using Channel4

const channel4 = require('channel4')

const {
  close,
  put,
  take,
} = channel4

const logPrefix = (
  prefix,
) => (
  value,
) => {
  console
  .log(
    prefix,
    value,
  )
}

const channel = channel4()

put(channel, 'A')
put(channel, 'B')

take(channel, logPrefix('first'))
take(channel, logPrefix('second'))
take(channel, logPrefix('third'))

put(channel, 'C')
put(channel, 'D') // Never logged

close(channel)

console.log('DONE')

// DONE
// first A
// second B
// third C