How to use the ember-concurrency.process function in ember-concurrency

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 machty / ember-concurrency / tests / dummy / app / components / color-square / component.js View on Github external
attributeBindings: 'style',
  style: Ember.computed('color', function() {
    let color = this.get('color');
    return `width: 100px; height: 100px; background-color: ${color}`;
  }),

  color: 'red',

  init() {
    this._super();
    if (this.get('autoStart')) {
      this.get('colorAlternator').start();
    }
  },

  colorAlternator: process(function * () {
    let colors = ['red', 'blue', 'green'];
    for (;;) {
      for (let color of colors) {
        this.set('color', color);
        yield sleep(this.get('ms'));
      }
    }
  }),

  click() {
    let process = this.get('colorAlternator');
    if (process.isRunning) {
      process.kill();
    } else {
      process.start();
    }
github machty / ember-concurrency / tests / dummy / app / components / ajax-progress / component.js View on Github external
import Ember from 'ember';
import { process, sleep } from 'ember-concurrency';

export default Ember.Component.extend({
  innerProgressStyle: Ember.computed('progress', function() {
    let width = Math.floor(this.get('progress') * 100);
    return `width: ${width}%`;
  }),

  progress: 0,
  status: "Ready",
  results: null,
  query: "csp",

  wikiSearcher: process(function * (query) {
    this.set('progress', 0.1);

    let countdown = 4;
    while (countdown--) {
      this.set('status', `Gearing up for an AJAX query in  ${countdown}`);
      this.set('progress', this.get('progress') + 0.02);
      yield sleep(1000);
    }

    this.set('status', `Performing AJAX query for ${query}...`);
    this.set('progress', 0.5);

    let encodedQuery = window.encodeURIComponent("query");
    let url = `https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=${encodedQuery}&callback=?`;

    let ajaxRequest = Ember.$.getJSON(url);
github machty / ember-concurrency / tests / dummy / app / components / yielding-promises / component.js View on Github external
import Ember from 'ember';
import { process } from 'ember-concurrency';

let delay = (ms) => {
  return new Ember.RSVP.Promise(r => {
    Ember.run.later(r, ms);
  });
};

export default Ember.Component.extend({
  status: "Ready",

  numInvocations: 0,

  promiseHandler: process(function * (promise) {
    try {
      this.set('status', "Resolving a promise...");
      let value = yield promise;
      this.set('status', `OK, promise resolved with ${value}`);
    } catch(e) {
      this.set('status', `Oh no, it rejected with a value of ${e}`);
    } finally {
      this.incrementProperty('numInvocations');
    }
  }),

  actions: {
    doFulfillPromise() {
      let promise = delay(1000).then(() => "HOORAY");
      this.get('promiseHandler').start(promise);
    },