• This is not a core part of ember-resources, but is an example utility to demonstrate a concept when authoring your own resources. However, this utility is still under the broader library's SemVer policy.

    A consuming app will not pay for the bytes of this utility unless imported.

    uses Resource to make ember-concurrency tasks reactive.


    Type Parameters

    • Return = unknown

    • Args extends unknown[] = unknown[]

    • LocalTask extends TaskIsh<Args, Return> = TaskIsh<Args, Return>

    Parameters

    • context: object
    • task: LocalTask
    • Optional thunk: (() => Args)
        • (): Args
        • Returns Args

    Returns TaskInstance<Return>

    Note

    ember-resources does not provide or depend on ember-concurrency. If you want to use task, you'll need to add ember-concurrency as a dependency in your project.

    Example

    When this.id changes, the task will automatically be re-invoked.

    import { tracked } from '@glimmer/tracking';
    import { restartableTask, timeout } from 'ember-concurrency';
    import { task as trackedTask } from 'ember-resources/util/ember-concurrency';

    class Demo {
    @tracked id = 1;

    searchTask = restartableTask(async () => {
    await timeout(200);
    await fetch('...');
    return 'the-value';
    })

    last = trackedTask(this, this.searchTask, () => [this.id]);
    }
    Available Properties:
    {{this.last.value}}
    {{this.last.isFinished}}
    {{this.last.isRunning}}
    {{this.last.value}}

    (and all other properties on a TaskInstance)

Generated using TypeDoc