Warn about attempting to push multiple values at once.

This commit is contained in:
David Braun 2017-10-08 15:35:50 -04:00
parent c56f4404f8
commit f2c26591a1
No known key found for this signature in database
GPG key ID: 5694EEC4D129BDCF
2 changed files with 24 additions and 9 deletions

View file

@ -38,7 +38,9 @@ describe(`Channel`, function () {
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 () {
@ -188,10 +190,9 @@ describe(`Channel object`, function () {
})().then(() => {
assert(false)
}).catch((reason) => {
assert.deepEqual(
reason,
new TypeError(`Can't push 'undefined' to channel, use close instead.`)
)
assert.deepEqual(reason, new TypeError(
`Can't push 'undefined' to channel, use close instead.`
))
})
})
@ -203,14 +204,26 @@ describe(`Channel object`, function () {
})().then(() => {
assert(false)
}).catch((reason) => {
assert.deepEqual(
reason,
new TypeError(`Can't push 'undefined' to channel, use close instead.`)
)
assert.deepEqual(reason, 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 () {
assert.throws(() => {
Channel().push(0).frozen = false