Add Channel.isChannel
.
This commit is contained in:
parent
74f5673752
commit
7d0d203c2e
3 changed files with 18 additions and 5 deletions
14
lib/index.js
14
lib/index.js
|
@ -34,6 +34,8 @@ const Order = (channel) => {
|
|||
return {order, promise}
|
||||
}
|
||||
|
||||
const prototype = {}
|
||||
|
||||
const Channel = function (bufferLength = 0) {
|
||||
let buffered = 0
|
||||
let closed = false
|
||||
|
@ -102,7 +104,7 @@ const Channel = function (bufferLength = 0) {
|
|||
resolvedIndex -= index.push
|
||||
}
|
||||
|
||||
const readOnly = Object.freeze({
|
||||
const readOnly = Object.assign(Object.create(prototype), {
|
||||
every: async (callbackfn, thisArg) => {
|
||||
for (;;) {
|
||||
const value = await readOnly.shift()
|
||||
|
@ -215,13 +217,12 @@ const Channel = function (bufferLength = 0) {
|
|||
})()
|
||||
|
||||
return output
|
||||
},
|
||||
|
||||
get value () {
|
||||
return lastValue
|
||||
}
|
||||
})
|
||||
|
||||
Object.defineProperty(readOnly, `value`, {get: () => lastValue})
|
||||
Object.freeze(readOnly)
|
||||
|
||||
const writeOnly = Object.freeze({
|
||||
close: () =>
|
||||
new Promise((resolve, reject) => {
|
||||
|
@ -299,6 +300,9 @@ Channel.from = (values) => {
|
|||
Channel.of = (...values) =>
|
||||
Channel.from(values)
|
||||
|
||||
Channel.isChannel = (arg) =>
|
||||
prototype.isPrototypeOf(arg)
|
||||
|
||||
Channel.select = (...methodPromises) => {
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
methodPromises.forEach(async (promise) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue