Merge multiple streams into one interleaved stream

License: MIT

Language: JavaScript


Merge (interleave) a bunch of streams.

build status


var stream1 = new Stream();
var stream2 = new Stream();

var merged = mergeStream(stream1, stream2);

var stream3 = new Stream();
//=> false


This is adapted from event-stream separated into a new module, using Streams3.



Type: function

Merges an arbitrary number of streams. Returns a merged stream.


A method to dynamically add more sources to the stream. The argument supplied to add can be either a source or an array of sources.


A method that tells you if the merged stream is empty.

When a stream is "empty" (aka. no sources were added), it could not be returned to a gulp task.

So, we could do something like this:

stream = require('merge-stream')();
// Something like a loop to add some streams to the merge stream
// stream.add(streamA);
// stream.add(streamB);
return stream.isEmpty() ? null : stream;

Gulp example

An example use case for merge-stream is to combine parts of a task in a project's gulpfile.js like this:

const gulp =          require('gulp');
const htmlValidator = require('gulp-w3c-html-validator');
const jsHint =        require('gulp-jshint');
const mergeStream =   require('merge-stream');

function lint() {
  return mergeStream(
gulp.task('lint', lint);



Project Statistics

Sourcerank 17
Repository Size 27.3 KB
Stars 178
Forks 16
Watchers 5
Open issues 0
Dependencies 2
Contributors 10
Tags 12
Last updated
Last pushed

Top Contributors See all

Stephen Sugden Shinnosuke Watanabe Steve Mao nervo Tsutomu Kawamura Dem Pilafian r-browser-app-team Fred K. Schott Jonathan Svenheden contra

Packages Referencing this Repo

Create a stream that emits events from multiple other streams
Latest release 2.0.0 - Updated - 178 stars

Recent Tags See all

v2.0.0 May 23, 2019
v1.0.1 November 25, 2016
v1.0.0 August 10, 2015
v0.1.8 June 30, 2015
v0.1.7 January 10, 2015
v0.1.6 September 25, 2014
v0.1.5 July 06, 2014
v0.1.4 July 06, 2014
v0.1.3 July 06, 2014
v0.1.2 June 26, 2014
v0.1.1 May 20, 2014
v0.0.1 May 19, 2014

Something wrong with this page? Make a suggestion

Last synced: 2019-09-10 12:22:54 UTC

Login to resync this repository