How to use the ember-concurrency.sleep 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 / 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(),
github machty / ember-concurrency / tests / dummy / app / components / x-music / component.js View on Github external
playMusic: task(function * () {
    let i = 0;
    while(i++ < 6) {
      this.set('value', i);
      yield sleep(150);
    }

    let AudioContext = window.AudioContext || window.webkitAudioContext;

    if (!AudioContext) {
      console.error("AudioContext not detected... perhaps web audio api not supported?");
      return;
    }

    let context, beepOscillator;

    try {
      context = new AudioContext();
      beepOscillator = context.createOscillator();
      beepOscillator.frequency.value = 300;
github machty / ember-concurrency / tests / dummy / app / components / x-task / component.js View on Github external
task: task('group', function * () {
    let i = 0;
    while(i++ < 6) {
      this.set('value', i);
      yield sleep(150);
    }
  }),
github machty / ember-concurrency / tests / dummy / app / components / color-square / component.js View on Github external
colorAlternator: process(function * () {
    let colors = ['red', 'blue', 'green'];
    for (;;) {
      for (let color of colors) {
        this.set('color', color);
        yield sleep(this.get('ms'));
      }
    }
  }),
github machty / ember-concurrency / tests / dummy / app / components / ajax-progress / component.js View on Github external
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);
    try {
      let response = Ember.RSVP.resolve(ajaxRequest.promise());
      this.set('status', "Search complete!");
      this.set('progress', 1);

      let results = response[3];
      this.set('results', results);