Merge multiple streams into one stream in sequence or parallel.

\href{https://npmjs.org/package/merge2}{\texttt{ }} \href{https://travis-ci.org/teambition/merge2}{\texttt{ }} \href{https://npmjs.org/package/merge2}{\texttt{ }}\hypertarget{md_sfcode_node_modules_merge2_README_autotoc_md17133}{}\doxysection{Install}\label{md_sfcode_node_modules_merge2_README_autotoc_md17133}
Install with \href{https://npmjs.org/package/merge2}{\texttt{ npm}}


\begin{DoxyCode}{0}
\DoxyCodeLine{npm install merge2 }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_merge2_README_autotoc_md17134}{}\doxysection{Usage}\label{md_sfcode_node_modules_merge2_README_autotoc_md17134}

\begin{DoxyCode}{0}
\DoxyCodeLine{const gulp = require('gulp')}
\DoxyCodeLine{const merge2 = require('merge2')}
\DoxyCodeLine{const concat = require('gulp-\/concat')}
\DoxyCodeLine{const minifyHtml = require('gulp-\/minify-\/html')}
\DoxyCodeLine{const ngtemplate = require('gulp-\/ngtemplate')}
\DoxyCodeLine{}
\DoxyCodeLine{gulp.task('app-\/js', function () \{}
\DoxyCodeLine{  return merge2(}
\DoxyCodeLine{      gulp.src('static/src/tpl/*.html')}
\DoxyCodeLine{        .pipe(minifyHtml(\{empty: true\}))}
\DoxyCodeLine{        .pipe(ngtemplate(\{}
\DoxyCodeLine{          module: 'genTemplates',}
\DoxyCodeLine{          standalone: true}
\DoxyCodeLine{        \})}
\DoxyCodeLine{      ), gulp.src([}
\DoxyCodeLine{        'static/src/js/app.js',}
\DoxyCodeLine{        'static/src/js/locale\_zh-\/cn.js',}
\DoxyCodeLine{        'static/src/js/router.js',}
\DoxyCodeLine{        'static/src/js/tools.js',}
\DoxyCodeLine{        'static/src/js/services.js',}
\DoxyCodeLine{        'static/src/js/filters.js',}
\DoxyCodeLine{        'static/src/js/directives.js',}
\DoxyCodeLine{        'static/src/js/controllers.js'}
\DoxyCodeLine{      ])}
\DoxyCodeLine{    )}
\DoxyCodeLine{    .pipe(concat('app.js'))}
\DoxyCodeLine{    .pipe(gulp.dest('static/dist/js/'))}
\DoxyCodeLine{\}) }

\end{DoxyCode}



\begin{DoxyCode}{0}
\DoxyCodeLine{const stream = merge2([stream1, stream2], stream3, \{end: false\})}
\DoxyCodeLine{//...}
\DoxyCodeLine{stream.add(stream4, stream5)}
\DoxyCodeLine{//..}
\DoxyCodeLine{stream.end() }

\end{DoxyCode}



\begin{DoxyCode}{0}
\DoxyCodeLine{// equal to merge2([stream1, stream2], stream3)}
\DoxyCodeLine{const stream = merge2()}
\DoxyCodeLine{stream.add([stream1, stream2])}
\DoxyCodeLine{stream.add(stream3) }

\end{DoxyCode}



\begin{DoxyCode}{0}
\DoxyCodeLine{// merge order:}
\DoxyCodeLine{//   1. merge `stream1`;}
\DoxyCodeLine{//   2. merge `stream2` and `stream3` in parallel after `stream1` merged;}
\DoxyCodeLine{//   3. merge 'stream4' after `stream2` and `stream3` merged;}
\DoxyCodeLine{const stream = merge2(stream1, [stream2, stream3], stream4)}
\DoxyCodeLine{}
\DoxyCodeLine{// merge order:}
\DoxyCodeLine{//   1. merge `stream5` and `stream6` in parallel after `stream4` merged;}
\DoxyCodeLine{//   2. merge 'stream7' after `stream5` and `stream6` merged;}
\DoxyCodeLine{stream.add([stream5, stream6], stream7) }

\end{DoxyCode}



\begin{DoxyCode}{0}
\DoxyCodeLine{// nest merge}
\DoxyCodeLine{// equal to merge2(stream1, stream2, stream6, stream3, [stream4, stream5]);}
\DoxyCodeLine{const streamA = merge2(stream1, stream2)}
\DoxyCodeLine{const streamB = merge2(stream3, [stream4, stream5])}
\DoxyCodeLine{const stream = merge2(streamA, streamB)}
\DoxyCodeLine{streamA.add(stream6) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_merge2_README_autotoc_md17135}{}\doxysection{API}\label{md_sfcode_node_modules_merge2_README_autotoc_md17135}

\begin{DoxyCode}{0}
\DoxyCodeLine{const merge2 = require('merge2') }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_merge2_README_autotoc_md17136}{}\doxysubsection{merge2()}\label{md_sfcode_node_modules_merge2_README_autotoc_md17136}
\hypertarget{md_sfcode_node_modules_merge2_README_autotoc_md17137}{}\doxysubsection{merge2(options)}\label{md_sfcode_node_modules_merge2_README_autotoc_md17137}
\hypertarget{md_sfcode_node_modules_merge2_README_autotoc_md17138}{}\doxysubsection{merge2(stream1, stream2, ..., stream\+N)}\label{md_sfcode_node_modules_merge2_README_autotoc_md17138}
\hypertarget{md_sfcode_node_modules_merge2_README_autotoc_md17139}{}\doxysubsection{merge2(stream1, stream2, ..., stream\+N, options)}\label{md_sfcode_node_modules_merge2_README_autotoc_md17139}
\hypertarget{md_sfcode_node_modules_merge2_README_autotoc_md17140}{}\doxysubsection{merge2(stream1, \mbox{[}stream2, stream3, ...\mbox{]}, stream\+N, options)}\label{md_sfcode_node_modules_merge2_README_autotoc_md17140}
return a duplex stream (merged\+Stream). streams in array will be merged in parallel.\hypertarget{md_sfcode_node_modules_merge2_README_autotoc_md17141}{}\doxysubsection{merged\+Stream.\+add(stream)}\label{md_sfcode_node_modules_merge2_README_autotoc_md17141}
\hypertarget{md_sfcode_node_modules_merge2_README_autotoc_md17142}{}\doxysubsection{merged\+Stream.\+add(stream1, \mbox{[}stream2, stream3, ...\mbox{]}, ...)}\label{md_sfcode_node_modules_merge2_README_autotoc_md17142}
return the merged\+Stream.\hypertarget{md_sfcode_node_modules_merge2_README_autotoc_md17143}{}\doxysubsection{merged\+Stream.\+on(\textquotesingle{}queue\+Drain\textquotesingle{}, function() \{\})}\label{md_sfcode_node_modules_merge2_README_autotoc_md17143}
It will emit \textquotesingle{}queue\+Drain\textquotesingle{} when all streams merged. If you set {\ttfamily end === false} in options, this event give you a notice that should add more streams to merge or end the merged\+Stream.\hypertarget{md_sfcode_node_modules_merge2_README_autotoc_md17144}{}\doxysubsubsection{stream}\label{md_sfcode_node_modules_merge2_README_autotoc_md17144}
{\itshape option} Type\+: {\ttfamily Readable} or {\ttfamily Duplex} or {\ttfamily Transform} stream.\hypertarget{md_sfcode_node_modules_merge2_README_autotoc_md17145}{}\doxysubsubsection{options}\label{md_sfcode_node_modules_merge2_README_autotoc_md17145}
{\itshape option} Type\+: {\ttfamily Object}.


\begin{DoxyItemize}
\item {\bfseries{end}} -\/ {\ttfamily Boolean} -\/ if {\ttfamily end === false} then merged\+Stream will not be auto ended, you should end by yourself. {\bfseries{Default\+:}} {\ttfamily undefined}
\item {\bfseries{pipe\+Error}} -\/ {\ttfamily Boolean} -\/ if {\ttfamily pipe\+Error === true} then merged\+Stream will emit {\ttfamily error} event from source streams. {\bfseries{Default\+:}} {\ttfamily undefined}
\item {\bfseries{object\+Mode}} -\/ {\ttfamily Boolean} . {\bfseries{Default\+:}} {\ttfamily true}
\end{DoxyItemize}

{\ttfamily object\+Mode} and other options({\ttfamily high\+Water\+Mark}, {\ttfamily default\+Encoding} ...) is same as Node.\+js {\ttfamily Stream}.\hypertarget{md_sfcode_node_modules_merge2_README_autotoc_md17146}{}\doxysection{License}\label{md_sfcode_node_modules_merge2_README_autotoc_md17146}
MIT © \href{https://www.teambition.com}{\texttt{ Teambition}} 