yet another async scheduler, this time supporting flexible runtime control flow based on declarative priority levels

This commit is contained in:
ansuz
2020-02-13 16:44:11 -05:00
parent b7b2685f14
commit 2d6626234b
2 changed files with 275 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
const Plan = require("../../lib/plan");
var rand_delay = function (f) {
setTimeout(f, Math.floor(Math.random() * 1500) + 250);
};
var plan = Plan(6).job(1, function (next) {
[1,2,3,4,5,6,7,8,9,10,11,12].forEach(function (n, i) {
plan.job(0, function (next) {
rand_delay(function () {
console.log("finishing job %s", n);
next();
});
});
});
console.log("finishing job 0");
next();
}).job(2, function (next) {
console.log("finishing job 13");
[
100,
200,
300,
400
].forEach(function (n, i) {
plan.job(3, function (next) {
rand_delay(function () {
console.log("finishing job %s", n);
next();
});
});
});
next();
}).done(function () { console.log("DONE"); }).start();
//console.log(plan);
//plan.start();