machty / ember-concurrency

ember-concurrency is an Ember Addon that enables you to write concise, worry-free, cancelable, restartable, asynchronous tasks.
http://ember-concurrency.com
MIT License
691 stars 157 forks source link

Error "@computed can only be used on accessors or fields..." using task decorator with modifiers #416

Closed davideferre closed 3 years ago

davideferre commented 3 years ago

Writing code like explained in the tutorial "Version 3: Preventing Concurrency (with Tasks)" throws an exception:

Error: Assertion Failed: @computed can only be used on accessors or fields, attempted to use it with seriesAddTask but that was a method. Try converting it to a getter (e.g. get seriesAddTask() {}) image

My code is:

import { task } from 'ember-concurrency';
....
@task({ drop: true })
    *seriesAddTask() {
        ....
    }

I'm using ember-concurrency 2.0.3.

Writing it in this other way works fine:

@(task(function* () {
    ....
}).drop()) seriesAddTask;
maxfierke commented 3 years ago

It sounds like you're maybe on an Ember version lower than 3.10? You may need to do this instead:

@task({ drop: true })
seriesAddTask = function*() {
   // ...
}
davideferre commented 3 years ago

It sounds like you're maybe on an Ember version lower than 3.10? You may need to do this instead:

@task({ drop: true })
seriesAddTask = function*() {
   // ...
}

No, I'm on ember 3.25...

maxfierke commented 3 years ago

No, I'm on ember 3.25...

@task only uses computed for Ember versions below 3.10 or on ember-concurrency 1.x. My next guess is that something else in your app is probably loading an earlier version of ember-concurrency, and not ember-concurrency 2.x. yarn why ember-concurrency is a good way to find out what other versions of ember-concurrency might be present, if you're using Yarn.

davideferre commented 3 years ago

I'm using npm but you have found the problem!

├── ember-concurrency@2.0.3 └─┬ ember-google-maps@3.3.0 └── ember-concurrency@1.3.0

There's a way to solve the problem without uninstalling ember-google-maps?

maxfierke commented 3 years ago

With yarn, you can force it with resolutions. Not sure if there's an npm equivalent? Otherwise, you may need to contact the upstream author to relax the dependency range or have them push a new version with v2 support.

davideferre commented 3 years ago

With yarn, you can force it with resolutions. Not sure if there's an npm equivalent? Otherwise, you may need to contact the upstream author to relax the dependency range or have them push a new version with v2 support.

Ok, thank you so much!