Skip to content

Instantly share code, notes, and snippets.

View dagda1's full-sized avatar

Paul dagda1

View GitHub Profile
@dagda1
dagda1 / bs2.js
Last active August 29, 2015 13:56
function BulkLoader(){
this.users = [];
this.companies = [];
this.contacts = [];
};
BulkLoader.prototype.iterator = function * () {
this.users = yield [{name: 'bob', email: 'bob@hotmail.com'}];
this.contacts = yield [{name: 'brian', email: 'brian@hotmail.com'}];
this.companies = yield [{name: 'company', email: 'company@hotmail.com'}];
BulkLoader.prototype.load = function() {
var self = this;
return async(function * () {
try {
self.users = yield getJSON('/users');
self.contacts = yield getJSON('/contacts');
self.companies = yield getJSON('/companies');
return self;
export default function async(generatorFunc) {
function continuer(verb, arg) {
var result;
try {
result = generator[verb](arg);
} catch (err) {
return RSVP.Promise.reject(err);
}
if (result.done) {
return result.value;
self.users = yield getJSON('/users');
return async(function * () {
var generator = generatorFunc();
var callback = continuer.bind(continuer, "next");
var errback = continuer.bind(continuer, "throw");
result = generator[verb](arg);
result = generator.next(arg);
self.users = yield getJSON('/users');