Last active
January 9, 2017 00:16
-
-
Save JeffML/eb5eb8eadf745e41dc731254944259cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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