Skip to content
This repository has been archived by the owner on Oct 31, 2018. It is now read-only.

Concurrency in this.queue() #31

Open
vsukhomlinov opened this issue Dec 21, 2014 · 3 comments
Open

Concurrency in this.queue() #31

vsukhomlinov opened this issue Dec 21, 2014 · 3 comments

Comments

@vsukhomlinov
Copy link

Multiple queue() calls within the es.through() handler get sent downstream in wrong order:

var es = require('event-stream');

var streamLine = es.through(function (line) {
    this.queue("*");
    this.queue("|"+line+'\n');
});

process.stdin.on('readable', function() {
    var streamLine1 = es.through(function (line) {
        this.queue('*');
        this.queue("|"+line+'\n');
    });

    process.stdin.pipe(es.split()).pipe(streamLine).pipe(process.stdout);
})

I'm testing it like this

$ printf "a\nb\n" | node pipeTest.js
*|a
*|b
**|
|

An interesting note is that calling streamLine1 from closure renders everything properly.

@dominictarr
Copy link
Owner

can you post the "correct" output that you are expecting?

@vsukhomlinov
Copy link
Author

I'd expect all queue() calls for the handler be executed sequentially within the function, like this

$ printf "a\nb\n" | node pipeTest.js
*|a
*|b
*|
*|

@dominictarr
Copy link
Owner

oh okay I see what the problem is now.
you are using the readable event the wrong way. that is part of the private streams2 api.
probably, this is causing you to pipe the same stream twice.

instead just do process.stdin.pipe(es.split()).pipe(streamLine).pipe(process.stdout)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants