Wednesday, 6 November 2019

Strange behavior with node streams

I'm build a library that works with node streams. Something I'm trying to do is to increase a bit of the developer ergonomics surrounding the pipe method on streams.The idea is to have a function that takes in any number of transforms, and then creates a passthrough that is piped through each of those transforms. The code snippet is below:​https://preview.redd.it/9ib8ateds2x31.png?width=1074&format=png&auto=webp&s=66ec292d056df2fedc7e9d2a9e231e84cfe0beb6The problem I'm running into is that this only works for the first transform that is passed.This example has an odd output:const stream = ... // stream of [1,2,3,4,5,6,7,8,9] const pipeline = pipe(map(n => n * 2), map(n => n * 2)); stream.pipe(pipeline); Instead of this outputing [ 4, 8, 12, 16, 20, 24, 28, 32, 36 ], it outputs [ 2, 4, 6, 8, 10, 12, 14, 16, 18 ], meaning that it only pipes through the first transform.I'm not 100% sure where I've gone wrong.

Submitted November 06, 2019 at 02:23PM by notAnotherJSDev

No comments:

Post a Comment