Skip to content

Instantly share code, notes, and snippets.

@JeffML
Last active January 9, 2017 00:16
Show Gist options
  • Save JeffML/eb5eb8eadf745e41dc731254944259cf to your computer and use it in GitHub Desktop.
Save JeffML/eb5eb8eadf745e41dc731254944259cf to your computer and use it in GitHub Desktop.
function run() {
var menu = { //...
}
var iceCreamChoices = new Combinator({ //...
});
var toppingChoices = new Combinator({ //...
});
var syrupChoices = new Combinator({ //...
});
var count = 0;
var total = iceCreamChoices.length * toppingChoices.length * syrupChoices.length;
var postCount = 0;
var postCountMax = 5;
_.each(iceCreamChoices, function (ic) {
_.each(toppingChoices, function (tp) {
_.each(syrupChoices, function (sy) {
var si = setInterval(() => {
if (postCount < postCountMax) {
clearInterval(si);
postChoice(ic, tp, sy);
}
}, 10);
})
})
});
function postChoice(ic, tp, sy) {
++postCount;
db.post({
choice: [ic, tp, sy]
}, function (err, doc) {
--postCount;
done(err);
});
}
function done(err) {
if (err) {
console.error(err);
process.exit(1);
}
console.log(`stored ${++count}`);
if (count === total) {
console.log('done');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment