Warn about attempting to push multiple values at once.
This commit is contained in:
parent
c56f4404f8
commit
f2c26591a1
2 changed files with 24 additions and 9 deletions
|
@ -232,6 +232,8 @@ const Channel = function (bufferLength = 0) {
|
||||||
order.reject(new TypeError(
|
order.reject(new TypeError(
|
||||||
`Can't push 'undefined' to channel, use close instead.`
|
`Can't push 'undefined' to channel, use close instead.`
|
||||||
))
|
))
|
||||||
|
} else if (arguments.length > 1) {
|
||||||
|
order.reject(new Error(`Can't push more than one value at a time.`))
|
||||||
} else {
|
} else {
|
||||||
pushes.push(order)
|
pushes.push(order)
|
||||||
setImmediate(processOrders)
|
setImmediate(processOrders)
|
||||||
|
|
|
@ -38,7 +38,9 @@ describe(`Channel`, function () {
|
||||||
assert.equal(await channel.shift(), 0)
|
assert.equal(await channel.shift(), 0)
|
||||||
})()
|
})()
|
||||||
|
|
||||||
await channel.push(0, 1, 2)
|
await channel.push(0)
|
||||||
|
await channel.push(1)
|
||||||
|
await channel.push(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe(`from`, function () {
|
describe(`from`, function () {
|
||||||
|
@ -188,10 +190,9 @@ describe(`Channel object`, function () {
|
||||||
})().then(() => {
|
})().then(() => {
|
||||||
assert(false)
|
assert(false)
|
||||||
}).catch((reason) => {
|
}).catch((reason) => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(reason, new TypeError(
|
||||||
reason,
|
`Can't push 'undefined' to channel, use close instead.`
|
||||||
new TypeError(`Can't push 'undefined' to channel, use close instead.`)
|
))
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -203,14 +204,26 @@ describe(`Channel object`, function () {
|
||||||
})().then(() => {
|
})().then(() => {
|
||||||
assert(false)
|
assert(false)
|
||||||
}).catch((reason) => {
|
}).catch((reason) => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(reason, new TypeError(
|
||||||
reason,
|
`Can't push 'undefined' to channel, use close instead.`
|
||||||
new TypeError(`Can't push 'undefined' to channel, use close instead.`)
|
))
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it(`disallows multiple values`, function () {
|
||||||
|
const channel = Channel()
|
||||||
|
|
||||||
|
return (async () => {
|
||||||
|
await channel.push(0, 1, 2)
|
||||||
|
})().then(() => {
|
||||||
|
assert(false)
|
||||||
|
}).catch((reason) => {
|
||||||
|
assert.deepEqual(reason, new Error(
|
||||||
|
`Can't push more than one value at a time.`))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it(`returns a frozen promise`, function () {
|
it(`returns a frozen promise`, function () {
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
Channel().push(0).frozen = false
|
Channel().push(0).frozen = false
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue