{"id":13806558,"url":"https://github.com/machty/ember-concurrency-decorators","last_synced_at":"2025-07-05T01:07:08.911Z","repository":{"id":20600006,"uuid":"90387517","full_name":"machty/ember-concurrency-decorators","owner":"machty","description":"Task decorators for ember-concurrency 1.x (merged into ember-concurrency 2.0)","archived":false,"fork":false,"pushed_at":"2022-12-10T16:51:02.000Z","size":1940,"stargazers_count":70,"open_issues_count":28,"forks_count":24,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-06-21T12:16:23.671Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/machty.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-05T14:59:54.000Z","updated_at":"2024-04-17T20:05:08.000Z","dependencies_parsed_at":"2023-01-11T20:54:32.746Z","dependency_job_id":null,"html_url":"https://github.com/machty/ember-concurrency-decorators","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/machty/ember-concurrency-decorators","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/machty%2Fember-concurrency-decorators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/machty%2Fember-concurrency-decorators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/machty%2Fember-concurrency-decorators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/machty%2Fember-concurrency-decorators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/machty","download_url":"https://codeload.github.com/machty/ember-concurrency-decorators/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/machty%2Fember-concurrency-decorators/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263641607,"owners_count":23493420,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T01:01:13.225Z","updated_at":"2025-07-05T01:07:08.889Z","avatar_url":"https://github.com/machty.png","language":"TypeScript","funding_links":[],"categories":["Packages"],"sub_categories":["ES6"],"readme":"# ember-concurrency-decorators\n\n[![Build Status](https://travis-ci.org/machty/ember-concurrency-decorators.svg)](https://travis-ci.org/machty/ember-concurrency-decorators)\n[![npm version](https://badge.fury.io/js/ember-concurrency-decorators.svg)](http://badge.fury.io/js/ember-concurrency-decorators)\n[![Download Total](https://img.shields.io/npm/dt/ember-concurrency-decorators.svg)](http://badge.fury.io/js/ember-concurrency-decorators)\n[![Ember Observer Score](https://emberobserver.com/badges/ember-concurrency-decorators.svg)](https://emberobserver.com/addons/ember-concurrency-decorators)\n[![Ember Versions](https://img.shields.io/badge/Ember.js%20Versions-%5E2.12%20%7C%7C%20%5E3.0-brightgreen.svg)](https://travis-ci.org/machty/ember-concurrency-decorators)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![dependencies](https://img.shields.io/david/machty/ember-concurrency-decorators.svg)](https://david-dm.org/machty/ember-concurrency-decorators)\n[![devDependencies](https://img.shields.io/david/dev/machty/ember-concurrency-decorators.svg)](https://david-dm.org/machty/ember-concurrency-decorators)\n\nThis Ember addon lets you use the\n[decorator syntax](https://github.com/tc39/proposal-decorators)\nfor declaring/configuring\n[ember-concurrency](https://ember-concurrency.com) tasks.\n\n## Deprecated/merged into ember-concurrency v2\n\nAll of the decorators provided by this repo were merged into Ember Concurrency v2; if you running Ember Concurrency 2.0.0+, you can remove this addon, and convert all of your `import {...} from 'ember-concurrency-decorators'` to `import {...} from 'ember-concurrency'`.\n\n## Installation\n\n⚠️👉 Check the [FAQ](#faq), if something isn't working or you're not sure what\nto do.\n\n### Stage 1 Decorators\n\nRequirements:\n\n- At least `ember-cli-babel@^7.7.2`\n- At least `@babel/core@^7.5.0` (as a transitive dependency via `ember-cli-babel`)\n- At least `ember-cli-typescript@^2.0.0`, if you want to use it with TypeScript\n- `@ember-decorators/babel-transforms` is _not_ installed\n- The rest of `@ember-decorators`, if present, is `^6.0.0`\n- Below Ember v3.10: [`ember-decorators-polyfill`][ember-decorators-polyfill]\n\n[ember-decorators-polyfill]: https://github.com/pzuraq/ember-decorators-polyfill\n\nThen install the `latest` release:\n\n```\nember install ember-concurrency-decorators\n```\n\n### Stage 2 Decorators\n\nIf you are still using stage 2 decorators, I recommend that you refactor away\nfrom them as soon as possible.\n\nRequirements:\n\n- at least `ember-cli-babel@^7.7.2`\n- `@ember-decorators/babel-transforms` _is_ installed\n- The rest of `@ember-decorators`, if present, is `^5.0.0` (below `6.0.0`)\n\nThen install the [`legacy`][stage-2] version:\n\n[stage-2]: https://github.com/machty/ember-concurrency-decorators/tree/v0.6.0\n\n```\nember install ember-concurrency-decorators@legacy\n```\n\nThe following documentation will not be accurate. Instead refer to the\n[docs for stage 2 decorators][stage-2].\n\n## Usage\n\n### Available decorators\n\n- **[`@task`](#task)**: turns a generator method into a task\n  - `@restartableTask`\n  - `@dropTask`\n  - `@keepLatestTask`\n  - `@enqueueTask`\n- **[`@taskGroup`](#taskgroup)**: creates a task group from a property\n  - `@restartableTaskGroup`\n  - `@dropTaskGroup`\n  - `@keepLatestTaskGroup`\n  - `@enqueueTaskGroup`\n- **[`@lastValue`](#lastvalue)**: alias a property to the result of a task with an optional default value\n\n#### `@task`\n\n```js\nimport Component from '@ember/component';\nimport { task } from 'ember-concurrency-decorators';\n\nexport default class ExampleComponent extends Component {\n  @task\n  *doStuff() {\n    // ...\n  }\n\n  // and then elsewhere\n  executeTheTask() {\n    // `doStuff` is still a `Task` object that can be `.perform()`ed\n    this.doStuff.perform();\n    console.log(this.doStuff.isRunning);\n  }\n}\n```\n\nYou can also pass further options to the task decorator:\n\n```js\n@task({\n  maxConcurrency: 3,\n  restartable: true\n})\n*doStuff() {\n  // ...\n}\n```\n\nYou can also use task lifecycle event hooks in your tasks:\n\n```js\n@task({ on: 'didInsertElement' })\n*doStuff() {\n  // ...\n}\n```\n\nFor your convenience, there are extra decorators for all [concurrency modifiers](http://ember-concurrency.com/docs/task-concurrency):\n\n| Shorthand          | Equivalent                     |\n| ------------------ | ------------------------------ |\n| `@restartableTask` | `@task({ restartable: true })` |\n| `@dropTask`        | `@task({ drop: true })`        |\n| `@keepLatestTask`  | `@task({ keepLatest: true })`  |\n| `@enqueueTask`     | `@task({ enqueue: true })`     |\n\nYou can still pass further options to these decorators, like:\n\n```js\n@restartableTask({ maxConcurrency: 3 })\n*doStuff() {\n  // ...\n}\n```\n\n##### Encapsulated Tasks\n\n\u003e [Encapsulated Tasks](http://ember-concurrency.com/docs/encapsulated-task) behave just like regular tasks, but with one crucial difference: the value of `this` within the task function points to the currently running TaskInstance, rather than the host object that the task lives on (e.g. a Component, Controller, etc). This allows for some nice patterns where all of the state produced/mutated by a task can be contained (encapsulated) within the Task itself, rather than having to live on the host object.\n\n```js\nimport Component from '@ember/component';\nimport { task } from 'ember-concurrency-decorators';\n\nexport default class ExampleComponent extends Component {\n  @task\n  doStuff = {\n    privateState: 123,\n    *perform() {\n      // ...\n    }\n  };\n\n  // and then elsewhere\n  executeTheTask() {\n    // `doStuff` is still a `Task` object that can be `.perform()`ed\n    this.doStuff.perform();\n    console.log(this.doStuff.isRunning);\n  }\n}\n```\n\nUnfortunately, encapsulated Tasks do not currently work well with TypeScript.\nSee the [TypeScript](#typescript-support) section for more details.\n\n#### `@taskGroup`\n\n```js\nimport Component from '@ember/component';\nimport { task, taskGroup } from 'ember-concurrency-decorators';\n\nexport default class ExampleComponent extends Component {\n  @taskGroup\n  someTaskGroup;\n\n  @task({ group: 'someTaskGroup' })\n  *doStuff() {\n    // ...\n  }\n\n  @task({ group: 'someTaskGroup' })\n  *doOtherStuff() {\n    // ...\n  }\n\n  // and then elsewhere\n  executeTheTask() {\n    // `doStuff` is still a `Task `object that can be `.perform()`ed\n    this.doStuff.perform();\n\n    // `someTaskGroup` is still a `TaskGroup` object\n    console.log(this.someTaskGroup.isRunning);\n  }\n}\n```\n\nYou can also pass further options to the task group decorator:\n\n```js\n@taskGroup({\n  maxConcurrency: 3,\n  drop: true\n}) someTaskGroup;\n```\n\nAs for `@task`, there are extra decorators for all [concurrency modifiers](http://ember-concurrency.com/docs/task-concurrency):\n\n| Shorthand               | Equivalent                          |\n| ----------------------- | ----------------------------------- |\n| `@restartableTaskGroup` | `@taskGroup({ restartable: true })` |\n| `@dropTaskGroup`        | `@taskGroup({ drop: true })`        |\n| `@keepLatestTaskGroup`  | `@taskGroup({ keepLatest: true })`  |\n| `@enqueueTaskGroup`     | `@taskGroup({ enqueue: true })`     |\n\nYou can still pass further options to these decorators, like:\n\n```js\n@dropTaskGroup({ maxConcurrency: 3 }) someTaskGroup;\n```\n\n#### `@lastValue`\n\nThis decorator allows you to alias a property to the result of a task. You can also provide a default value to use before the task has completed.\n\n```js\nimport Component from '@ember/component';\nimport { task } from 'ember-concurrency-decorators';\nimport { lastValue } from 'ember-concurrency-decorators';\n\nexport default class ExampleComponent extends Component {\n  @task\n  *someTask() {\n    // ...\n  }\n\n  @lastValue('someTask')\n  someTaskValue;\n\n  @lastValue('someTask')\n  someTaskValueWithDefault = 'A default value';\n}\n```\n\n## FAQ\n\n### Compatibility and Weird Errors\n\nThe specification for decorators in broader JavaScript has been in flux.\nUnfortunately, that means if you have been an early adopter of decorators in\nyour Ember application, you may need to deal with some API churn.\n\n[(You can read an excellent discussion on decorators here.)](https://www.pzuraq.com/coming-soon-in-ember-octane-part-1-native-classes/)\n\nCheck the above [requirements](#installation) to see what version you need to\ninstall.\n\nIf you are sure, that you fulfilled the requirements correctly, but are still\nexperiencing weird errors, install\n[`ember-cli-dependency-lint`][ember-cli-dependency-lint] to ensure that you are\nnot accidentally including outdated versions of `ember-decorators` as transitive\ndependencies.\n\n[ember-cli-dependency-lint]: https://github.com/salsify/ember-cli-dependency-lint\n\nIf it's still not working after that, please [create an issue][new-issue].\n\n[new-issue]: https://github.com/machty/ember-concurrency-decorators/issues/new\n\n### TypeScript Support\n\nYou can use this package with TypeScript, _but_ unfortunately decorators cannot\nyet change the type signature of the decorated element. This is why you may get\ntype errors like:\n\n```ts\nimport { task } from 'ember-concurrency-decorators';\n\nexport default class Foo {\n  @task\n  *doStuff(this: Foo) {\n    // ...\n  }\n\n  executeTheTask() {\n    this.doStuff.perform();\n  }\n}\n```\n\n```\nTS2339: Property 'perform' does not exist on type '() =\u003e IterableIterator\u003cany\u003e'.\n```\n\nSee [ember-concurrency's documentation on TypeScript][ec-ts-docs] for more\ndetails and workarounds.\n\nSee also [issue #30][issue-typescript] and [PR #56][pr-typescript] for more\nhistorical context and alternative design ideas.\n\n[ec-ts-docs]: http://ember-concurrency.com/docs/typescript\n[issue-typescript]: https://github.com/machty/ember-concurrency-decorators/issues/30\n[pr-typescript]: https://github.com/machty/ember-concurrency-decorators/pull/56\n\n### Do I _need_ this addon?\n\nNo! If you are using Ember v3.10.0 or above, you can use `ember-concurrency`\ndirectly, like this:\n\n```js\nimport { task } from 'ember-concurrency';\n\nclass Foo {\n  @(task(function*() {\n    // ...\n  }).restartable())\n  doStuff;\n\n  executeTheTask() {\n    this.doStuff.perform();\n  }\n}\n```\n\n_However_:\n\n- This syntax will not continue to work with the new \"static decorators\"\n  proposal that is set to replace the stage 1 decorators eventually.\n- This does not properly type-check with TypeScript. See\n  [TypeScript Support](#typescript-support) for more details.\n- I think this looks hideous, but that is just an opinion.\n\nEventually, all work in `ember-concurrency-decorators` will likely flow back\ninto `ember-concurrency` at some point. Until then, we want to mature and\ntest-drive the API here first.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmachty%2Fember-concurrency-decorators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmachty%2Fember-concurrency-decorators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmachty%2Fember-concurrency-decorators/lists"}