async read() {
    if (this.data.length > 0) {
      const value = this.data.splice(0, 1)[0];

      // Insert awaiting write on buffer
      if (this.writes.length > 0) {
        const write = this.writes.splice(0, 1)[0];
        this.data.push(write.val);
        write.res();
      }

      return value;
    }

    if (this.closed) {
      return null;
    }

    if (this.writes.length > 0) {
      const write = this.writes.splice(0, 1)[0];
      write.res();
      return write.val;
    }

    return new Promise((resolve, reject) => {
      this.reads.push({
        res: resolve,
        rej: reject
      });
    });
  }
/**
   * Reads value from channel. Returns promise that resolves when value is available
   * @return {any} - Value read
   */
Reads value from channel. Returns promise that resolves when value is available
@return {any} - Value read
Reads value from channel . Returns promise that resolves when value is available @return { any } - Value read
async read() {
    if (this.data.length > 0) {
      const value = this.data.splice(0, 1)[0];
      if (this.writes.length > 0) {
        const write = this.writes.splice(0, 1)[0];
        this.data.push(write.val);
        write.res();
      }
      return value;
    }
    if (this.closed) {
      return null;
    }
    if (this.writes.length > 0) {
      const write = this.writes.splice(0, 1)[0];
      write.res();
      return write.val;
    }
    return new Promise((resolve, reject) => {
      this.reads.push({
        res: resolve,
        rej: reject
      });
    });
  }
async read ( ) { if ( this . data . length > 0 ) { const value = this . data . splice ( 0 , 1 ) [ 0 ] ; if ( this . writes . length > 0 ) { const write = this . writes . splice ( 0 , 1 ) [ 0 ] ; this . data . push ( write . val ) ; write . res ( ) ; } return value ; } if ( this . closed ) { return null ; } if ( this . writes . length > 0 ) { const write = this . writes . splice ( 0 , 1 ) [ 0 ] ; write . res ( ) ; return write . val ; } return new Promise ( ( resolve , reject ) => { this . reads . push ( { res : resolve , rej : reject } ) ; } ) ; }
Reads value from channel.
Reads value from channel .
// Insert awaiting write on buffer