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

`trackedTask` does not work with newer ec async task format

Open mydea opened this issue 2 years ago • 3 comments

The new async task format from ember-concurrency is quite cool (https://github.com/machty/ember-concurrency/releases/tag/2.3.2), however it does not seem to work with trackedTask.

My usage:

menuItemsTask = trackedTask(this, this.loadMenuItemsTask, () => []);

loadMenuItemsTask = task(async () => {
  // do something here
});

I get the error:

ember-concurrency.js:71 
 Uncaught (in promise) TypeError: Cannot use 'in' operator to search for 'perform' in undefined
    at task (ember-concurrency.js:71:25)
    at new MainMenuService (menu.js:42:258)

mydea avatar Sep 02 '22 08:09 mydea

I have see the same error as ^^. Is there a work around here?

basz avatar Oct 11 '22 17:10 basz

Seems to come from here... https://github.com/NullVoxPopuli/ember-resources/blob/main/ember-resources/src/util/ember-concurrency.ts#L67 were task is undefined at the time it is used.

Using this construct worked for me...

define loadMenuItemsTask before trackedTask uses it

loadMenuItemsTask = task(async () => {
  // do something here
});

menuItemsTask = trackedTask(this, this.loadMenuItemsTask, () => []);

basz avatar Oct 11 '22 18:10 basz

I haven't gotten around to it yet, bu the plan is to allow usables to be registered with ember-resources, so ember-concurrency's task could be a trackedTask all on its own like this:

import { task } from 'ember-concurrency';
import { use } from 'ember-resources';

// ...
@use loadMenuItemsTask = task(async () => {
  // do something here
});

But I don't know how to change the type of the returned task to a TaskInstance, so suggestions welcome (and this is partially why I haven't done this yet)

NullVoxPopuli avatar Oct 11 '22 18:10 NullVoxPopuli

👋 I was also planning on using the trackedTask but faced this same issue.

esbanarango avatar Mar 07 '23 23:03 esbanarango

Latest version should work. Lemme know!

NullVoxPopuli avatar Apr 27 '23 10:04 NullVoxPopuli

Latest version should work. Lemme know!

Hey, @NullVoxPopuli I'm having this issue currently with ember-resources 5.4.1. Could you explain what should work, please? Moving the trackedTask after the declaration of the task works for me but I am not sure if we want this

Thanks!

Luisetelo avatar Mar 06 '24 13:03 Luisetelo

What version of ember concurrency are you using?

This is the usage that should work: https://github.com/NullVoxPopuli/ember-resources/issues/611#issue-1359854067

NullVoxPopuli avatar Mar 06 '24 14:03 NullVoxPopuli

What version of ember concurrency are you using?

Just updated to 4.0.0

This is the usage that should work: #611 (comment)

I can confirm it does work 😄 I was confused by this comment: https://github.com/NullVoxPopuli/ember-resources/issues/611#issuecomment-1275113299

Luisetelo avatar Mar 06 '24 14:03 Luisetelo

Excellent! I'll close this issue. Thanks!

The other comment is more a dream for a simpler api

NullVoxPopuli avatar Mar 06 '24 15:03 NullVoxPopuli