How to use ember-concurrency - 10 common examples

To help you get started, we’ve selected a few ember-concurrency 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 miguelcobain / ember-yeti-table / tests / dummy / app / pods / docs / async / controller.js View on Github external
loadDataTask = function*({ paginationData, sortData, filterData }) {
    yield timeout(250);

    let params = {
      sortBy: sortData.map((s) => s.prop),
      sortDir: sortData.map((s) => s.direction),
      pageNumber: paginationData.pageNumber,
      pageSize: paginationData.pageSize,
      filter: filterData.filter
    };

    let users = yield this.store.query('user', params);

    // we need to inform Yeti Table about the total number of rows
    // for pagination to work correctly. Check out the pagination guide.
    this.set('totalRows', users.get('meta.totalRows'));

    return users;
github machty / ember-concurrency / tests / dummy / app / docs / examples / modal-fun / controller.js View on Github external
return o;
}

// BEGIN-SNIPPET modal-fun-controller
import { task, timeout, taskGroup } from 'ember-concurrency';

let PAUSE_FOREVER = Ember.RSVP.defer().promise;

export default Ember.Controller.extend({
  openWizard: task({
    perform: function * () {
      this.get('stepOne').perform();
      yield PAUSE_FOREVER;
    },

    states: taskGroup().restartable(),
    currentState: alias('states.last'),

    next: taskByName('next'),
    prev: taskByName('prev'),

    stepOne: state({
      title: "Step 1",
      next: 'stepTwo',
      index: 0,
    }),

    stepTwo: state({
      perform: function * () {
        while (true) {
          yield timeout(500);
          this.set('title', reverse(this.title));
github machty / ember-concurrency / tests / dummy / app / docs / examples / task-groups / controller.js View on Github external
import { computed } from '@ember/object';
import Controller from '@ember/controller';
import { taskGroup } from 'ember-concurrency';

// BEGIN-SNIPPET task-groups
export default Controller.extend({
  everything:         taskGroup(),
  everythingDropped:  taskGroup().drop(),
  everythingEnqueue:  taskGroup().enqueue(),
  everythingRestart:  taskGroup().restartable(),
  everythingDropped3: taskGroup().maxConcurrency(3).drop(),
  everythingEnqueue3: taskGroup().maxConcurrency(3).enqueue(),
  everythingRestart3: taskGroup().maxConcurrency(3).restartable(),

  taskGroups: computed(function () {
    return [
      this.get('everything'),
      this.get('everythingDropped'),
      this.get('everythingEnqueue'),
      this.get('everythingRestart'),
      this.get('everythingDropped3'),
      this.get('everythingEnqueue3'),
      this.get('everythingRestart3'),
    ];
github machty / ember-concurrency / tests / dummy / app / docs / examples / task-groups / controller.js View on Github external
import { computed } from '@ember/object';
import Controller from '@ember/controller';
import { taskGroup } from 'ember-concurrency';

// BEGIN-SNIPPET task-groups
export default Controller.extend({
  everything:         taskGroup(),
  everythingDropped:  taskGroup().drop(),
  everythingEnqueue:  taskGroup().enqueue(),
  everythingRestart:  taskGroup().restartable(),
  everythingDropped3: taskGroup().maxConcurrency(3).drop(),
  everythingEnqueue3: taskGroup().maxConcurrency(3).enqueue(),
  everythingRestart3: taskGroup().maxConcurrency(3).restartable(),

  taskGroups: computed(function () {
    return [
      this.get('everything'),
      this.get('everythingDropped'),
      this.get('everythingEnqueue'),
      this.get('everythingRestart'),
      this.get('everythingDropped3'),
      this.get('everythingEnqueue3'),
      this.get('everythingRestart3'),
    ];
  }),
});
// END-SNIPPET
github machty / ember-concurrency / tests / dummy / app / components / events-example / component.js View on Github external
waiter: task(function * () {
    let event = yield waitForEvent(document.body, 'click');
    return event;
  }),
// END-SNIPPET
github machty / ember-concurrency / tests / dummy / app / components / events-example / component.js View on Github external
emberEventedLoop: task(function * () {
    while(true) {
      let event = yield waitForEvent(this, 'fooEvent');
      this.set('emberEvent', event);
    }
  }).on('didInsertElement'),
// END-SNIPPET
github machty / ember-concurrency / tests / dummy / app / components / async-iterator / component.js View on Github external
let obs = window.Rx.Observable.interval(100).take(50 + 1).do(v => {
      if (!this.isDestroyed) {
        this.set('obsValue', v);
      }
    });

    let ai = asyncIterator(obs);
    if (this.bufferType) {
      ai[this.bufferType]();
    }

    while (true) {
      let { value, done } = yield ai.next();
      if (done) { break; }
      this.set('value', value);
      yield sleep(300); // pretend to be some async work
    }
  }).autoStart(),
github machty / ember-concurrency / tests / dummy / app / components / x-music / component.js View on Github external
beepOscillator.frequency.value = 300;

      let beepGain = context.createGain();
      beepGain.gain.value = 0;

      beepOscillator.connect(beepGain);
      beepOscillator.type = 'triangle';
      beepGain.connect(context.destination);

      beepOscillator.start(0);

      let bps = this.get('bpm') / 60.0;
      let halfTimeout = 1 / bps / 2 * 1000;

      // sleep randomly so that multiple x-musics don't annoying start at the same time.
      yield sleep(Math.random() * 1000);

      for (;;) {
        // main
        beepOscillator.frequency.value = 100 + Math.random() * 600;
        beepGain.gain.setTargetAtTime(0.5, context.currentTime, 0.01);
        this.set('isPlaying', true);
        yield sleep(halfTimeout);

        beepGain.gain.setTargetAtTime(0, context.currentTime, 0.01);
        this.set('isPlaying', false);
        yield sleep(halfTimeout);
      }
    } finally {
      if (context) {
        context.close();
      }
github machty / ember-concurrency / tests / dummy / app / components / async-iterator-evented / component.js View on Github external
myTask: task(function * () {
    this.set('value', "START");

    let ai = asyncIterator.fromEvent(this, 'onEvent');
    if (this.bufferType) {
      ai[this.bufferType]();
    }

    while (true) {
      let { value, done } = yield ai.next();
      if (done) { break; }
      this.set('value', value.foo);
      yield sleep(800); // pretend to be some async work
    }
  }).autoStart(),
github machty / ember-concurrency / tests / dummy / app / components / x-music / component.js View on Github external
beepGain.connect(context.destination);

      beepOscillator.start(0);

      let bps = this.get('bpm') / 60.0;
      let halfTimeout = 1 / bps / 2 * 1000;

      // sleep randomly so that multiple x-musics don't annoying start at the same time.
      yield sleep(Math.random() * 1000);

      for (;;) {
        // main
        beepOscillator.frequency.value = 100 + Math.random() * 600;
        beepGain.gain.setTargetAtTime(0.5, context.currentTime, 0.01);
        this.set('isPlaying', true);
        yield sleep(halfTimeout);

        beepGain.gain.setTargetAtTime(0, context.currentTime, 0.01);
        this.set('isPlaying', false);
        yield sleep(halfTimeout);
      }
    } finally {
      if (context) {
        context.close();
      }

      if (beepOscillator) {
        beepOscillator.stop();
      }
    }
  }).autoStart(),