How to use ember-concurrency-decorators - 2 common examples

To help you get started, we’ve selected a few ember-concurrency-decorators examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NullVoxPopuli / react-vs-ember / concurrency / ember / src / ui / components / async-button / component.ts View on Github external
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { timeout } from 'ember-concurrency';
import { task, lastValue } from 'ember-concurrency-decorators';

export default class AsyncButton extends Component {
  @tracked clickCount = 0;

  // get lastCoords() {
  //   return this.clickTask.lastSuccessful.value;
  // }
  @lastValue('clickTask') lastCoords!: string;

  @task
  clickTask = function*(e: MouseEvent) {
    yield timeout(2000);

    this.clickCount++;

    return `${e.x} x ${e.y}`;
  };
}
github jdaviderb / JFrogfy / src / services / youtube.ts View on Github external
}

  play(track: Track): any {
    if (this.controller && this.task) {
      this.controller.abort();
      this.controller = new AbortController();
      this.signal = this.controller.signal;
      this.task.cancel();
    }
    // @ts-ignore
    this.task = this._load.perform(track);
    return this.task;
  }

  // @ts-ignore
  @task({ maxConcurrency: 2, drop: true })
  *_load(track: Track): any {
    let audio;
    const options = { method: 'get', signal: this.signal };

    try {
      this.audio.pause();
      const queryParams = encodeURI(`?artist=${track.artist}&song=${track.name}`);
      const response = yield fetch(this.host + this.endpoint + queryParams, options);
      const data = yield response.json();
      audio = decodeURIComponent(data.video);
      this.audio.play(audio);
    } catch(error) {
      this.audio.tracksManager.nextPlay();
    }

    return audio;

ember-concurrency-decorators

decorator syntax for declaring/configuring ember-concurrency tasks

MIT
Latest version published 4 years ago

Package Health Score

53 / 100
Full package analysis