reduce: Throw TypeError if the channel contains no values and initialValue
is not provided.
This commit is contained in:
parent
7d0d203c2e
commit
ecc01b686e
3 changed files with 77 additions and 54 deletions
10
lib/index.js
10
lib/index.js
|
@ -182,14 +182,20 @@ const Channel = function (bufferLength = 0) {
|
|||
|
||||
await readOnly.forEach((currentValue) => {
|
||||
if (previousValueDefined) {
|
||||
previousValue = callbackfn(previousValue, currentValue, 0, readOnly)
|
||||
previousValue = callbackfn(previousValue, currentValue)
|
||||
} else {
|
||||
previousValue = currentValue
|
||||
previousValueDefined = true
|
||||
}
|
||||
})
|
||||
|
||||
return previousValue
|
||||
if (previousValueDefined) {
|
||||
return previousValue
|
||||
} else {
|
||||
throw new TypeError(
|
||||
`No values in channel and initialValue wasn't provided.`
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
shift: function () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue