grncdr / merge-stream

Merge multiple streams into one interleaved stream
MIT License
214 stars 16 forks source link

Merged streams don't continue #32

Closed JacobDB closed 5 years ago

JacobDB commented 5 years ago

I'm not sure if the title makes any sense, but I'll do my best to explain.

I've got a gulp task that loops through some folders and runs some processes against all the files in each folder. These get added together with merge-stream. Once each folder has been processed and merged back together in to one stream, I then want to emit a notification to indicate that the task ran and completed. However, it seems that nothing after return MERGED_STREAMS is firing.

My full scripts task can be found on my new-site repository, but this is the relevant bit:

return MERGED_STREAMS
    // prevent breaking on error
    .pipe(plugins.plumber({
        errorHandler: on_error,
    }))
    // notify that task is complete, if not part of default or watch
    .pipe(plugins.gulpif(gulp.seq.indexOf("scripts") > gulp.seq.indexOf("default"), plugins.notify({
        title:   "Success!",
        message: "Scripts task complete!",
        onLast:  true,
    })))
    // push task to ran_tasks array
    .on("data", () => {
        if (ran_tasks.indexOf("scripts") < 0) {
            ran_tasks.push("scripts");
        }
    })
    .on("end", () => {
        console.log("reached the end"); // never happens
        return resolve();
    });

Any idea what could be causing this? I'm at a complete loss.

JacobDB commented 5 years ago

I figured out a different approach to accomplish what I was trying to do, but would still like to know what the problem is.

grncdr commented 5 years ago

I'm not familiar with what most of these gulp things you're using do, but I noticed this:

plugins.gulpif(gulp.seq.indexOf("scripts") > gulp.seq.indexOf("default"), ...)

It seems likely to me that doesn't do what you want, since the conditon is only evaluated once when your program starts.

JacobDB commented 5 years ago

So that stuff is to handle different notifications; I notify for each individual task, but combine them in to one notification when gulp or gulp watch is ran. Never had any issues with that in the past, still working well today.

I'm going to go ahead and close this issue, I think the problem was that a promise was returning too early and breaking things.