Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's even better if you use `yield` or `async/await`:

    activate(params) {
      let fabric_response = yield this.http.get(`${ this.url_base }/fabrics`)
      return fabric_response.content.map( fabric => {
          let cluster_response = yield this.http.get(`${ this.url_base }/fabrics/${ fabric.name }/clusters`)
          if(fabric.clusters_exist) {
              this.fabrics.push({"name": fabric.name, "clusters": cluster_response.content});
          }
      });
    }
EDIT: note that I am very sleepy and probably did a poor job of this =)


I was at a meetup yesterday where Axel Rauschmayer explained what's new in ES6, and especially the use of generators and yield was to me a mindblowing new way of programming.

Yours is a nice example of using yield to turn asynchronous code synchronous.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: