ember-concurrency
ember-concurrency copied to clipboard
task.last is the same as taskGroup.last
If task belongs to group, last
, lastRunning
, lastPerformed
, lastSuccessful
, lastComplete
, lastErrored
, lastCanceled
, lastIncomplete
, performCount
properties would be properties of group, not of task. That means it's impossible to get a last value or last error of a particular task, if it belongs to group. It would be great to mention this in API documentation.
Unfortunately, this severely limits the usefulness of task groups. It's necessary to be able to see the .last of each task in the group as well as the .last of the group.
I've read this a few times over but I'm still confused as to what the behavior you're seeing is... could you write out some pseudocode or try and explain it a different way?
Nevermind, I understand it and will try and take a look at this today (not sure how intense the refactor would be to fix this)
@mwpastore I agree this should all Just Work but what's the use case for being able to distinguish between the task.last and taskGroup.last?
@machty for example, if we have two or more tasks that can update/delete the same entity in database, we need to use a task group to prevent them from running at the same time. But if we need to display error or last returned value for each task separately (i.e. in different places on the page), we can't
@machty when tasks belong to a group, performCount
for the individual task returns the performCount for the entire group instead of the task itself. Whereas properties suchas .concurrency
will give you the independant results from the task vs group.
Give this a try
init() {
this._super(...arguments);
this.recreateIssue();
},
recreateIssue() {
this.taskIssueLogger.perform();
//do the dishes once
this.dishesTask.perform();
},
taskIssueLogger: task(function*() {
while (true) {
this.mowingLawnTask.perform();
console.log(
"dishesPerformCount",
this.dishesTask.performCount,
"mowingLawnPerformCount",
this.mowingLawnTask.performCount,
"choreGroupPerformCount",
this.chores.performCount
);
console.log(
"dishesConcurrency",
this.dishesTask.concurrency,
"mowingLawnConcurrency",
this.mowingLawnTask.concurrency,
"choreGroupConcurrency",
this.chores.concurrency
);
yield timeout(200);
}
}),
chores: taskGroup(),
dishesTask: task(function*(component) {
yield console.log("doing dishes!");
}).group("chores"),
mowingLawnTask: task(function*(component) {
yield timeout(3000);
yield console.log("I am always mowing the lawn.. it takes a while");
}).group("chores")
Then after a few iterations.... even though we performed the dishes task once, we get the following output.
dishesPerformCount 18 mowingLawnPerformCount 18 choreGroupPerformCount 18
dishesConcurrency 0 mowingLawnConcurrency 15 choreGroupConcurrency 15
I would expect the dishesTask to have a perform count of 1.