Spawn task experiment 2
Tests how fast it is to run gulp tasks in child processes
This is a fork of Spawn task experiment to allow to pass some information into
child process. I sent a pullRequest but never got an answer, so I'm posting this
so I can use it in npm.
Run task in child process:
var makeItFaster = require('spawn-task-experiment').spawn;
gulp.task('whatever', makeItFaster(function() {
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var concat = require('gulp-concat');
return gulp.src(['app/index.js', 'app/**/*.js'])
.pipe(sourcemaps.init())
.pipe(concat('all.js'))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('.build/scripts'));
}));
Run task in worker pool:
var makeItFaster = require('spawn-task-experiment').workerPool();
gulp.task('whatever', makeItFaster(function() {
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var concat = require('gulp-concat');
return gulp.src(['app/index.js', 'app/**/*.js'])
.pipe(sourcemaps.init())
.pipe(concat('all.js'))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('.build/scripts'));
}));
Notes:
- All wrapped functions need to be self-contained
- Using worker pool prevents parent process exit, so it might be usable only when watch is running
- Worker pool starts re-using child processes only after maxConcurrentWorkers limit has been reached (default is
cpus().length
)