Skip to content

Instantly share code, notes, and snippets.

@liondancer
Created January 28, 2017 07:21
Show Gist options
  • Save liondancer/059c126dbca032a55a49294859941cff to your computer and use it in GitHub Desktop.
Save liondancer/059c126dbca032a55a49294859941cff to your computer and use it in GitHub Desktop.
Promise.all(logSources.map(logSource => {
logSource.popAsync().then(log => {
minheap.insert({
ts: log.date.getTime(),
source: i,
data: log
})
});
}).then(
while (minheap.heapList.length) {
let heapNode = minheap.popMin();
let currTimestamp = heapNode['ts'];
printer.print(heapNode.data);
let nextMinTimestamp = minheap.getPeakTimestamp();
while (currTimestamp <= nextMinTimestamp) {
logSources[heapNode['source']].popAsync().then(log => {
if (log) {
let logtime = log.date.getTime();
if (logtime <= nextMinTimestamp) {
printer.print(log);
currTimestamp = logtime;
} else {
minheap.insert({
ts: logtime,
source: heapNode["source"],
data: log
});
break;
}
}
});
}
}
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment