ember-concurrency icon indicating copy to clipboard operation
ember-concurrency copied to clipboard

get all task instances

Open st-h opened this issue 8 years ago • 1 comments

I was trying to get all instances of a given task but could not find any method or property for doing so. I thought I could get that from the scheduler, but as soon as I created a computed property on _scheduler.activeTaskInstances I ended up with an error that I need to call set when trying to modify the activeTaskInstances. Not quite sure what is going on, but it's not part of the api anyways. Finally I ended up pushing any new task to a dedicated array, which seems to work just fine, but I was wondering if it might be a nice idea to expose the task instances so they could be easily referenced. Currently we only seem to be able to get the last instance. What do you think?

st-h avatar Nov 12 '17 23:11 st-h

I've been looking for this too. I'd like to delete a bunch of records 1 by one, and show the status of each in the template.

deleteClassTask: task(function* (schoolClass) {
  yield schoolClass.destroyRecord()
}).enqueue(),

// returns something like { 5: instance, 6: instance, ... }
deleteClassInstances: computed('deleteClass.allInstances.[]', function () {
  const instances = this.deleteClassTask.allInstances // this could be handy
  return instances.reduce((acc, instance) => {
    const classId = instance.args[0].id // not sure if args is public api or not
    return { ...acc, [classId]: instance }
  }, {})
}),

actions: {
  deleteClasses() { selectedClasses.forEach((c) => this.deleteClassTask.perform(c))
},
{{#each selectedClasses as |class| }}
  {{#let (get deleteClassInstances class.id) as |deletionInstance|}}
    {{class.name}} {{if deletionInstance.isRunning "deleting" "queued"}}
  {{/let}}
{{/each}}

(this code isn't perfect, just a rough idea of what could be done if task.allInstances was a thing). It may very well be better to just keep track of a separate property of performed instances separately and insert into it for each perform call

Techn1x avatar Nov 19 '20 03:11 Techn1x