Skip to content
This repository has been archived by the owner on Apr 2, 2019. It is now read-only.

output stream does not preserve order of input stream #3

Closed
nlacasse opened this issue Sep 18, 2013 · 3 comments
Closed

output stream does not preserve order of input stream #3

nlacasse opened this issue Sep 18, 2013 · 3 comments

Comments

@nlacasse
Copy link
Contributor

If the mapper function is asynchronous, the output stream is not guaranteed to have the same order as the input stream. This violates the semantics of "map".

Here is a test to illustrate the problem:

exports ['stream comes back in the correct order'] = function (test) {
  var input = [3, 2, 1]

  var delayer = map(function(data, cb){
    setTimeout(function () {
      cb(null, data)
    }, 100 * data)
  })

  readStream(delayer, function (err, output) {
    it(output).deepEqual(input)
    test.done()
  })

  writeArray(input, delayer)
}

And the resulting error:

test/
  stream comes back in the correct order
    AssertionError: [1,2,3] deepEqual [3,2,1]
@dominictarr
Copy link
Owner

you are correct.

I would happily take a pull request to fix this.

When I need this functionality, i use this https://github.com/dominictarr/pull-paramap
because pull-streams are simpler than node streams (for streams of objects) and handle back pressure better.

@parshap
Copy link

parshap commented Oct 14, 2013

What if you don't need this behavior? This adds overhead and delays streaming in those cases. Could this be an option?

@dominictarr
Copy link
Owner

@parshap it's really easy to make a thing that does that with https://github.com/dominictarr/through
it should be a separate module, if you write it, I'll link it from the map-stream readme.

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

3 participants