Skip to content
This repository has been archived by the owner on Nov 1, 2019. It is now read-only.

ember-concurrency + ember-cli-typescript + native classes = type safe 🥳

License

Notifications You must be signed in to change notification settings

buschtoens/ember-concurrency-typescript

Repository files navigation

ember-concurrency-typescript

Build Status npm version Download Total Ember Observer Score
ember.js ember-cli ember-cli-babel
code style: prettier dependencies devDependencies

Use ember-concurrency fully type-checked with ember-cli-typescript & native class syntax.

Installation

ember install ember-concurrency-typescript

If you haven't already, you also need to install ember-concurrency and ember-cli-typescript:

ember install ember-concurrency ember-cli-typescript

Usage

import { task, taskGroup, timeout } from 'ember-concurrency';

class Foo {
  slowGreeting = task(function*(this: Foo, delay: number, name: string) {
    yield timeout(delay);
    return `Hello, ${name}!`;
  });

  someRestartableTask = task(function*(this: Foo) {
    // ...
  }).restartable();

  someTaskGroup = taskGroup()
    .enqueue()
    .maxConcurrency(1);

  someGroupTask = task(function*(this: Foo) {
    // ...
  }).group('someTaskGroup');

  anotherGroupTask = task(function*(this: Foo) {
    // ...
  }).group('someTaskGroup');

  async greetTomDale() {
    // Parameters and return type are inferred correctly!
    const greeting = await this.slowGreeting.perform(1000, 'Tom Dale');
    console.log(greeting);
  }
}

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.