I have 3 tasks that I want to process and when those 3 tasks are done I want to do the following:
With Grunt
I had a long process for all this. Here is what I have tried with Gulp
gulp.task('libs', function () {
return gulp.src('js/libs/*.js')
.pipe(concat('01.libs.js', {newLine: ';'}))
.pipe(gulp.dest('min'));
});
gulp.task('plugins', function () {
return gulp.src('js/plugins/*.js')
.pipe(concat('02.plugins.js', {newLine: ';'}))
.pipe(gulp.dest('min'));
});
gulp.task('apps', function () {
return gulp.src('js/apps/**/*.js')
.pipe(concat('03.apps.js', {newLine: ';'}))
.pipe(gulp.dest('min'));
});
gulp.task('scripts', ['libs', 'plugins', 'apps'], function () {
return gulp .src('min/*.js')
.pipe(concat('testFile.js', {newLine: ';\r\n'}))
.pipe(rename({suffix: '.min.v' + pkg.version }))
.pipe(gulp.dest('min'))
.pipe(notify({ message: 'Scripts minified'}));
});
This works but I want to just stream the output rather than write out 3 intermediate files only to then concat those.
So I then tried:
function libs () {
return gulp.src('js/libs/*.js')
.pipe(concat('01.libs.js', {newLine: ';'}));
}
function plugins () {
return gulp.src('js/plugins/*.js')
.pipe(concat('02.plugins.js', {newLine: ';'}));
}
function apps () {
return gulp.src('js/apps/**/*.js')
.pipe(concat('03.apps.js', {newLine: ';'}));
}
So then my build
would be:
gulp.task('build', function () {
return libs()
.pipe(plugins())
.pipe(apps())
.pipe(concat('TestFile.js', {newLine: ';\r\n'}))
.pipe(rename({suffix: '.min.v' + pkg.version }))
.pipe(gulp.dest('min'));
});
This doesnt work.
So I tried Q
:
function allOfThem () {
return Q.all(libs(), plugins(), apps());
}
gulp.task('build', function () {
return allOfThem().then(function (one, two, three) {
console.log(one, two, three);
});
});
This I guess works but no data in the callback for then
.
I'm lost. What's the best way to achieve this?
Concurrent tasks progress at the same time in the worker system but they don't progress simultaneously. Parallel tasks are executed by different workers at the same time. Concurrency refers to how a worker system handles multiple tasks while parallelism refers to how a worker system handles a single task.
If you have several tasks that can be run in parallel, but still need to wait for all the tasks to end, you can easily achieve this using the Task. WhenAll() method in . NET Core. This will upload the first file, then the next file.
A continuation task (also known just as a continuation) is an asynchronous task that's invoked by another task, known as the antecedent, when the antecedent finishes.
The ContinueWith function is a method available on the task that allows executing code after the task has finished execution. In simple words it allows continuation. Things to note here is that ContinueWith also returns one Task. That means you can attach ContinueWith one task returned by this method.
Use event-stream.merge
var es = require('event-stream');
gulp.task('build', function () {
return es.merge(libs(), plugins(), apps())
.pipe(concat('TestFile.js', {newLine: ';\r\n'}))
.pipe(rename({suffix: '.min.v' + pkg.version }))
.pipe(gulp.dest('min'));
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With