Commit 29b7c2ed authored by Johannes Bill's avatar Johannes Bill

bla

parent a32fa7e1
var holidayMapping = require('./holidayMapping.json'); var holidayMapping = require('./holidayMapping.json');
var easterSunday = require('./easterSunday'); var easterSunday = require('./easterSunday');
var restRequest = require('./restRequests'); var restRequest = require('./restRequests');
var SimplQueue = require('./simplQueue');
var easterSundays = {}; var easterSundays = {};
var fixedHolidays = { var fixedHolidays = {
...@@ -107,7 +108,6 @@ function Holidays(year) { ...@@ -107,7 +108,6 @@ function Holidays(year) {
cb(null, options); cb(null, options);
} }
}); });
} }
function isInEpochSpan(date, epochSpan) { function isInEpochSpan(date, epochSpan) {
......
function SimplQueue(finisher) { function SimplQueue(finisher) {
this._finisher = finisher;
this._queue = []; this._queue = [];
this._started = false; this._started = false;
this._boundHandler = this._handler.bind(this);
} }
SimplQueue.prototype.push = function (cb) { SimplQueue.prototype.push = function (cb) {
this._queue.push(cb); this._queue.push(cb);
...@@ -11,13 +11,17 @@ SimplQueue.prototype.push = function (cb) { ...@@ -11,13 +11,17 @@ SimplQueue.prototype.push = function (cb) {
next(this._handler.bind(this)); next(this._handler.bind(this));
} }
}; };
SimplQueue.prototype.finish = function(finisher) {
this._finisher = finisher;
this._start();
};
SimplQueue.prototype.start = function () { SimplQueue.prototype._start = function () {
if (this._started) return; if (this._started) return;
this._started = true; this._started = true;
var next = this._queue.shift(); var next = this._queue.shift();
if (next) if (next)
next(this._handler.bind(this)); next(this._boundHandler);
else this._finisher(); else this._finisher();
}; };
...@@ -25,28 +29,34 @@ SimplQueue.prototype._handler = function (err) { ...@@ -25,28 +29,34 @@ SimplQueue.prototype._handler = function (err) {
if (err) return this._finisher(err); if (err) return this._finisher(err);
var next = this._queue.shift(); var next = this._queue.shift();
if (next) { if (next) {
next(this._handler.bind(this)); next(this._boundHandler);
} }
else this._finisher(null); else this._finisher(null);
}; };
module.exports = SimplQueue; module.exports = SimplQueue;
function doStuff() {
var queue = new SimplQueue(function (err) {
console.log(err);
console.log("finished");
});
for (var i = 0; i < 100; i++) {
queue.push(function (cb) {
setTimeout(function () {
if(Math.random() > 0.9)
return cb(new Error("muh"));
console.log(+new Date());
cb(null);
}, 50)
})
}
}
doStuff(); //function doStuff() {
\ No newline at end of file // var queue = new SimplQueue();
// var res = [];
// for (var i = 0; i < 200; i++) {
// queue.push(function (cb) {
// setTimeout(function () {
// if(Math.random() > 1)
// return cb(new Error("muh"));
// res.push(+new Date());
// cb(null);
// }, 10)
// });
// var time0 = process.hrtime();
// queue.finish(function (err) {
// if(err) return console.log(err);
// var time = process.hrtime(time0);
// console.log(time[0] * 1000 + time[1]*1e-6);
//// console.log(res);
// })
// }
//}
//
//doStuff();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment