Closed NextSeason closed 5 years ago
I've tried to use several packages for ordering streams, but none worked for me. I've tried to modify merge-stream but failed. The problem is that some streams participate in multiple merged streams (e.g. the same stream is used for creating a file and passing that file into concatenation stream).
const PassThrough = require('readable-stream/passthrough');
const merge = function (/*streams...*/) {
var sources = []
var output = new PassThrough({objectMode: true})
output.setMaxListeners(0)
output.add = add
output.isEmpty = isEmpty
output.on('unpipe', end)
Array.prototype.slice.call(arguments).forEach(add)
output.pause()
next()
return output
function next () {
if (isEmpty()) {
end()
return
}
var source = sources.shift()
source.once('end', next.bind(null))
source.once('error', output.emit.bind(output, 'error'))
source.pipe(output, {end: false})
source.resume()
}
function add (source) {
if (Array.isArray(source)) {
source.forEach(add)
return this
}
source.pause()
sources.push(source)
return this
}
function isEmpty () {
return sources.length == 0;
}
function end (source) {
sources.splice(0)
if (output.readable) { output.end() }
}
}
@NextSeason This may work in your case. If nobody see an error in my code, I will have to follow the Grunt way, create files with one task and after that concatenate them with another task.
Still waiting for @NextSeason to respond. Comment and we can reopen this.
My requirement is that I want to replace some strings with texts which I will read them from some files, but before doing this, I need to do some changes to the files which will be read and inject into other files. So I want to merge the two streams together and the second one has to wait for the finish of the first one.
What shall I do?