Skip to content

Commit

Permalink
create[Read|Write]Channel -> [Read|Write]Channel
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianRossouw committed Sep 2, 2014
1 parent 54221ca commit efb4f94
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 65 deletions.
28 changes: 14 additions & 14 deletions README.md
Expand Up @@ -83,12 +83,12 @@ if (!process.argv[2]) {

var jschan = require('jschan');
var session = jschan.spdyClientSession({ port: 9323 });
var sender = session.createWriteChannel();
var sender = session.WriteChannel();

var cmd = {
Args: process.argv.slice(3),
Cmd: process.argv[2],
StatusChan: sender.createReadChannel(),
StatusChan: sender.ReadChannel(),
Stderr: process.stderr,
Stdout: process.stdout,
Stdin: process.stdin
Expand Down Expand Up @@ -152,8 +152,8 @@ initiator in 'write' mode, with
Channels are unidirectional, but they can be nested (more on that
later).

<a name="session.createWriteChannel"></a>
#### session.createWriteChannel()
<a name="session.WriteChannel"></a>
#### session.WriteChannel()

Creates a Channel in 'write mode', e.g. a `streams.Writable`.
The channel follows the interface defined in
Expand All @@ -180,8 +180,8 @@ streams methods. Moreover, you can nest channels by including them
in a message, like so:

```js
var chan = session.createWriteChannel();
var ret = chan.createReadChannel();
var chan = session.WriteChannel();
var ret = chan.ReadChannel();

ret.on('data', function(res) {
console.log('response', res);
Expand All @@ -190,14 +190,14 @@ ret.on('data', function(res) {
chan.write({ returnChannel: ret });
```

<a name="channel.createReadChannel"></a>
#### channel.createReadChannel()
<a name="channel.ReadChannel"></a>
#### channel.ReadChannel()

Returns a nested read channel, this channel will wait for data from the
other party.

<a name="channel.createWriteChannel"></a>
#### channel.createWriteChannel()
<a name="channel.WriteChannel"></a>
#### channel.WriteChannel()

Returns a nested write channel, this channel will buffer data up until
is received by the other party. It fully respect backpressure.
Expand Down Expand Up @@ -234,8 +234,8 @@ session.on('channel', function server(chan) {

function client() {
// chan is a Writable stream
var chan = session.createWriteChannel();
var ret = chan.createReadChannel();
var chan = session.WriteChannel();
var ret = chan.ReadChannel();
var called = false;

ret.on('data', function(res) {
Expand Down Expand Up @@ -315,8 +315,8 @@ Example:
```js
var jschan = require('jschan');
var session = jschan.websocketClientSession('ws://localhost:3000');
var chan = session.createWriteChannel();
var ret = chan.createReadChannel();
var chan = session.WriteChannel();
var ret = chan.ReadChannel();

ret.on('data', function(res) {
console.log(res);
Expand Down
4 changes: 2 additions & 2 deletions examples/memory.js
Expand Up @@ -14,8 +14,8 @@ session.on('channel', function server(chan) {
});

function client() {
var chan = session.createWriteChannel();
var ret = chan.createReadChannel();
var chan = session.WriteChannel();
var ret = chan.ReadChannel();
var called = false;

ret.on('data', function(res) {
Expand Down
4 changes: 2 additions & 2 deletions examples/rexec/client.js
Expand Up @@ -12,12 +12,12 @@ if (!process.argv[2]) {
var jschan = require('../../');
var session = jschan.spdyClientSession({ port: 9323 });

var sender = session.createWriteChannel();
var sender = session.WriteChannel();

var cmd = {
Args: process.argv.slice(3),
Cmd: process.argv[2],
StatusChan: sender.createReadChannel(),
StatusChan: sender.ReadChannel(),
Stderr: process.stderr,
Stdout: process.stdout,
Stdin: process.stdin
Expand Down
1 change: 0 additions & 1 deletion examples/rexec/server.js
@@ -1,4 +1,3 @@

'use strict';

var jschan = require('../../');
Expand Down
6 changes: 3 additions & 3 deletions lib/channels.js
Expand Up @@ -14,15 +14,15 @@ function Channel(session, id) {

inherits(Channel, Transform);

Channel.prototype.createWriteChannel = function() {
Channel.prototype.WriteChannel = function() {
return this._session._createWriteChannel(this);
};

Channel.prototype.createReadChannel = function() {
Channel.prototype.ReadChannel = function() {
return this._session._createReadChannel(this);
};

Channel.prototype.createByteStream = function() {
Channel.prototype.ByteStream = function() {
return this._session._createByteStream(this);
};

Expand Down
4 changes: 2 additions & 2 deletions lib/encoder.js
Expand Up @@ -32,10 +32,10 @@ function Encoder(session, channels) {
var newChan;

if (chan.readChannel) {
newChan = that.encodingChannel.createWriteChannel();
newChan = that.encodingChannel.WriteChannel();
chan.pipe(newChan);
} else if (chan.writeChannel) {
newChan = that.encodingChannel.createReadChannel();
newChan = that.encodingChannel.ReadChannel();
newChan.pipe(chan);
} else {
throw new Error('specify readChannel or writeChannel property for streams not in the current channels');
Expand Down
2 changes: 1 addition & 1 deletion lib/memory/session.js
Expand Up @@ -56,7 +56,7 @@ MemorySession.prototype._createByteStream = function() {
return result;
};

MemorySession.prototype.createWriteChannel = function createWriteChannel() {
MemorySession.prototype.WriteChannel = function WriteChannel() {
var count = EventEmitter.listenerCount(this, 'channel');
var chan = this._createWriteChannel();

Expand Down
2 changes: 1 addition & 1 deletion lib/spdy/client.js
Expand Up @@ -150,7 +150,7 @@ ClientSession.prototype._createWriteChannel = function(parent) {
return createChannel(this, WriteChannel, parent.id);
};

ClientSession.prototype.createWriteChannel = function() {
ClientSession.prototype.WriteChannel = function() {
return createChannel(this, WriteChannel, '0');
};

Expand Down
2 changes: 1 addition & 1 deletion lib/stream/session.js
Expand Up @@ -151,7 +151,7 @@ StreamSession.prototype._createByteStream = function(parent) {
return createChannel(this, ByteStream, parent);
};

StreamSession.prototype.createWriteChannel = function createWriteChannel() {
StreamSession.prototype.WriteChannel = function WriteChannel() {
return this._createWriteChannel();
};

Expand Down

0 comments on commit efb4f94

Please sign in to comment.