Protomux.from
This commit is contained in:
parent
1c3c559d99
commit
534c417ed0
|
@ -67,6 +67,10 @@ Options include:
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### `mux = Protomux.from(stream | muxer, [options])`
|
||||||
|
|
||||||
|
Helper to accept either an existing muxer instance or a stream (which creates a new one).
|
||||||
|
|
||||||
#### `const p = mux.addProtocol(opts)`
|
#### `const p = mux.addProtocol(opts)`
|
||||||
|
|
||||||
Add a new protocol.
|
Add a new protocol.
|
||||||
|
|
5
index.js
5
index.js
|
@ -107,6 +107,7 @@ module.exports = class Protomux {
|
||||||
this.corked = 0
|
this.corked = 0
|
||||||
this.backlog = backlog
|
this.backlog = backlog
|
||||||
this.onacceptprotocol = onacceptprotocol || (() => this._unopened < this.backlog)
|
this.onacceptprotocol = onacceptprotocol || (() => this._unopened < this.backlog)
|
||||||
|
this.isProtomux = true
|
||||||
|
|
||||||
this._unopened = 0
|
this._unopened = 0
|
||||||
this._batch = null
|
this._batch = null
|
||||||
|
@ -117,6 +118,10 @@ module.exports = class Protomux {
|
||||||
this.stream.on('close', this._shutdown.bind(this))
|
this.stream.on('close', this._shutdown.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static from (other, opts) {
|
||||||
|
return other.isProtomux === true ? other : new Protomux(other, opts)
|
||||||
|
}
|
||||||
|
|
||||||
sendKeepAlive () {
|
sendKeepAlive () {
|
||||||
this.stream.write(this._alloc(0))
|
this.stream.write(this._alloc(0))
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue