Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function channel(buffer = buffers.expanding()) {
let closed = false
let takers = []
if (process.env.NODE_ENV !== 'production') {
check(buffer, is.buffer, INVALID_BUFFER)
}
function checkForbiddenStates() {
if (closed && takers.length) {
throw internalErr(CLOSED_CHANNEL_WITH_TAKERS)
}
if (takers.length && !buffer.isEmpty()) {
throw internalErr('Cannot have pending takers with non empty buffer')
}
}
function put(input) {
if (process.env.NODE_ENV !== 'production') {
checkForbiddenStates()
check(input, is.notUndef, UNDEFINED_INPUT_ERROR)
}
export function actionChannel(pattern, buffer) {
if (process.env.NODE_ENV !== 'production') {
check(pattern, is.pattern, 'actionChannel(pattern,...): argument pattern is not valid')
if (arguments.length > 1) {
check(buffer, is.notUndef, 'actionChannel(pattern, buffer): argument buffer is undefined')
check(buffer, is.buffer, `actionChannel(pattern, buffer): argument ${buffer} is not a valid buffer`)
}
}
return makeEffect(effectTypes.ACTION_CHANNEL, { pattern, buffer })
}