Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ember-concurrency: an experience report

ember-concurrency: an experience report

An informal talk given at the EmberTO meetup in June, 2017

Reg Braithwaite

June 05, 2017
Tweet

More Decks by Reg Braithwaite

Other Decks in Programming

Transcript

  1. ember-concurrency ember-concurrency is an Ember Addon that makes it easy

    to write concise, robust, and beautiful asynchronous code. --http://ember-concurrency.com/ Reginald @raganwald Braithwaite, PagerDuty Inc.
  2. tasks and instances aTask = task(function * () { const

    { geolocation, store } = this.get(...); const coords = yield geolocation.getCoords(); const result = yield store.getNearbyStores(coords); this.set('result', result); }); anInstance = someTask.perform(); Reginald @raganwald Braithwaite, PagerDuty Inc.
  3. concurrency protocols task(function * () { // ... }).drop() (ember-concurrency

    calls these "modifiers") Reginald @raganwald Braithwaite, PagerDuty Inc.
  4. ! this.set('isLoading', true); this.xhr = fetch(id).then( success => { this.set('isLoading',

    false); // ... }, failure => { this.set('isLoading', false); // ... }); Reginald @raganwald Braithwaite, PagerDuty Inc.
  5. progress const chunks = _.chunk(incidents, CHUNK_SIZE); let done = 0;

    this.set('done', done); for (const theseIncidents of chunks) { yield this.resolve(theseIncidents); done = done + theseIncidents.length); this.set('done', done); } Reginald @raganwald Braithwaite, PagerDuty Inc.
  6. sharing one task task(function * (promissoryThunk) { let result; yield

    promissoryThunk().then(value => { result = value; }); return result; }).enqueue() Reginald @raganwald Braithwaite, PagerDuty Inc.
  7. task groups tasks: taskGroup().enqueue(), handlePing: task(function * () { //

    ... }).group('tasks'), submitUpdate: task(function * () { // ... }).group('tasks') Reginald @raganwald Braithwaite, PagerDuty Inc.