Skip to content

Commit

Permalink
Make pipe work with close
Browse files Browse the repository at this point in the history
  • Loading branch information
tyoshino committed Feb 20, 2015
1 parent e1cc665 commit 02e1a6c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
8 changes: 6 additions & 2 deletions reference-implementation/lib/experimental/operation-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ export function pipeOperationStreams(readable, writable) {

if (readable.state === 'readable' && writable.state === 'writable') {
const op = readable.read();
const status = writable.write(op.argument);
jointOps(op, status);
if (op.type === 'data') {
jointOps(op, writable.write(op.argument));
} else {
jointOps(op, writable.close(op.argument));
return;
}

continue;
}
Expand Down
17 changes: 12 additions & 5 deletions reference-implementation/test/experimental/operation-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,25 +188,32 @@ test.only('Pipe', t => {

const helloStatus = wos0.write('hello');
wos0.write('world');
wos0.close();

pipeOperationStreams(ros0, wos1);

t.equals(ros1.state, 'waiting');

ros1.window = 10;
ros1.window = 20;

t.equals(ros1.state, 'waiting');

ros1.ready.then(() => {
t.equals(ros1.state, 'readable');
const op1 = ros1.read();
t.equals(op1.argument, 'hello');
const op0 = ros1.read();
t.equals(op0.type, 'data');
t.equals(op0.argument, 'hello');

op0.complete('hi');

op1.complete('hi');
t.equals(ros1.state, 'readable');
const op1 = ros1.read();
t.equals(op1.type, 'data');
t.equals(op1.argument, 'world');

t.equals(ros1.state, 'readable');
const op2 = ros1.read();
t.equals(op2.argument, 'world');
t.equals(op2.type, 'close');

t.equals(helloStatus.state, 'waiting');
helloStatus.ready.then(() => {
Expand Down

0 comments on commit 02e1a6c

Please sign in to comment.