Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sharing Functionalities example not working for serial and parallel tasks. #87

Open
Smesharikable opened this issue Jan 21, 2019 · 1 comment

Comments

@Smesharikable
Copy link

I tried to use Sharing Functionalities from README as an example to configure my tasks but it seems to not working, because this in function arguments of series and parallel stay bound to the Global object.

There is a gulpfile.js to reproduce:

var util = require('util');

var gulp = require('gulp');
var DefaultRegistry = require('undertaker-registry');

function ConfigRegistry(config){
  DefaultRegistry.call(this);
  this.config = config;
}

util.inherits(ConfigRegistry, DefaultRegistry);

ConfigRegistry.prototype.set = function set(name, fn) {
  // The `DefaultRegistry` uses `this._tasks` for storage.
  var task = this._tasks[name] = fn.bind(this.config);
  return task;
};

// `taker.registry` will reset each task in the registry with
// `ConfigRegistry.prototype.set` which will bind them to the config object.
gulp.registry(new ConfigRegistry({
  config: {
    src: './src',
    build: './build',
    bindTo: '0.0.0.0:8888'
  }
}));

gulp.task('dummy', function(cb) {
  // OK
  console.log('Config: ' + JSON.stringify(this.config));
  cb();
})

gulp.task('test-series', gulp.series('dummy', function(cb) {
  // undefined
  console.log('Config: ' + JSON.stringify(this.config));
  cb();
}));

gulp.task('test-parallel', gulp.parallel('dummy', function(cb) {
  // undefined
  console.log('Config: ' + JSON.stringify(this.config));
  cb();
}))
@phated
Copy link
Member

phated commented Apr 6, 2019

When passing a function into a series or parallel call, it avoids the task system. This is something I've been thinking about a lot and don't have a solution for currently (for example, every anonymous function would be registered as "anonymous" in the task system, breaking all sorts of things).

@phated phated added this to Nice to Have in v5 Oct 21, 2020
@phated phated removed this from Nice to Have in v5 Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants