lukeed / taskr

A fast, concurrency-focused task automation tool.
MIT License
2.53k stars 74 forks source link

Task not waiting for `this.start` to finish with `{parallel: true}` #174

Closed danny-andrews closed 8 years ago

danny-andrews commented 8 years ago

When I yield a task which yields the result of running two or more tasks in parallel, they don't seem to be run (or at least it seems fly isn't waiting for them to finish). Example:

x.a = function * () {
  this.log('A');
};
x.b = function * () {
  this.log('B');
}

If I write a task like the following:

x.printStuff = function * () {
  yield this.start(['a', 'b'], {parallel: true});
}

I get the following printed in the console (notice no 'A' or 'B' being logged)

[16:33:40] Flying with ...
[16:33:40] Starting printStuff
[16:33:40] Finished printStuff in 1 ms

However, if I write a task like this:

x.printStuff = function * () {
  yield [this.start('a'), this.start('b')];
}

I get the expected:

[16:38:26] Flying with ...
[16:38:26] Starting printStuff
[16:38:26] Starting a
[16:38:26] A
[16:38:26] Starting b
[16:38:26] B
[16:38:26] Finished lint in 2 ms
[16:38:26] Finished test in 2 ms
[16:38:26] Finished printStuff in 4 ms

TLDR:

this.start(['taskA', 'taskB'], {parallel: true}) !=
  [this.start('taskA'), this.start('taskB')]
lukeed commented 8 years ago

Parallel tasks are intentionally not awaited. They're told that no one cares when they finish, so they don't bother telling anyone.

And I'm pretty sure the .log() messages don't appear because they write into the current Fly instance. If it's been terminated, then there's nothing to write into.

That said, i can see how this is concerning when looking at console output. 💭

A surefire test would be to handle/write into files, since this takes the context of the test outside of the Fly instance. You'll find that files/file contents are created even after the "Finished" console message has been printed.

danny-andrews commented 8 years ago

That makes perfect sense, and I'm actually happy with the yield [this.start('a'), this.start('b')]; workaround. :) Thanks!

lukeed commented 8 years ago

👍 Cool, okay to close?

@brj do you think it's worth the extra effort & LOC to listen for the last parallel task to finish?