Using objects / passing keys down to now-and-later
pkozlowski-opensource opened this issue · 2 comments
The code in master uses now-and-later
where one can pass either an array or an object with functions to execute but it seems that there is no way to pass an object down to now-and-later.
If I understand your intentions correctly passing objects was a way to "name" anonymous functions so if someone uses tasks being anonymous functions in Gulp4 they would still get meaningful timing info. I was imagining that orchestrator would build an objects with functions to execute, "naming" those functions using task names, function names or a generated id (as the last resort). If so we need to find a way of passing down an object with those functions through bach.
Just to make the discussion more concrete, here is the use-case I'm having on my mind:
gulp = require('gulp4');
gulp.task(function foo(done) {...});
gulp.task('bar', function (done) {...});
var baz = function (done) {...});
gulp.task('default', ['foo', 'bar', baz]);
For the foo
function we can easily get a name / key from the function name itself, for bar
we don't have it so would use a task name and for baz
we've got nothing so would have to generate a key.
Now, those names / ids are important to properly report timing / duration of each task and I was under the impression that this is what an object-as-argument was introduced in now-and-later. If so we need to find a way of passing this info down to now-and-later. Honestly I'm not sure what would be a nice API here, something like this maybe, perhaps: bach.parallel(foo, {bar: bar})
? Or bach.parallel({foo: foo, bar: bar})
?
I must admit that I'm still not at ease with new layering so I might be talking rubbish here. In any case the functional use-case I'm after here is timing tasks in Gulp4. Thoughts?
The object syntax was going to be the way to pass names down but then I remembered that order isn't guaranteed for object iteration, and I would hate gulp to break between versions of node that change versions of v8. I have instead decided to store metadata about each task using a WeakMap shim (which will be a regular WM when node supports it). I hope to have something more concrete to point you at later today.
The WeakMap shim is working really well. See https://github.com/phated/undertaker/blob/master/index.js - I have an outstanding issue on the shim to remove its native dependency (even though it is optional, could still cause issues).