constructor (
    config,
    connect = _connect
  ) {
    this.id = _CONNECTION_IDGEN++
    this._conn = null
    this._pending = []
    this._open = true
    this._error = null
    this._handleConnectionError = this._handleConnectionError.bind(this)
    this._handleConnectionTerminated = this._handleConnectionTerminated.bind(
      this
    )
    this._connectionErrorCode = config.connectionErrorCode
    this._receiveTimeout = null
    this._receiveTimeoutStarted = false
    this._receiveTimeoutId = null

    this._config = config

    connect(config)
      .then(conn => {
        this._clearConnectionTimeout()
        if (!this._open) {
          return conn.close()
        }
        this._conn = conn

        setupReader(this)
          .catch(this._handleConnectionError)

        const pending = this._pending
        this._pending = null
        for (let i = 0; i < pending.length; i++) {
          this.write(pending[i])
        }
      })
      .catch(this._handleConnectionError)

    this._connectionTimeoutFired = false
    this._connectionTimeoutId = this._setupConnectionTimeout()
  }
Create new instance
@param {ChannelConfig} config - configuration for this channel.