Add Channel.isChannel.

This commit is contained in:
David Braun 2017-10-11 21:50:59 -04:00
parent 74f5673752
commit 7d0d203c2e
No known key found for this signature in database
GPG key ID: 5694EEC4D129BDCF
3 changed files with 18 additions and 5 deletions

View file

@ -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) => {