Created
January 28, 2017 07:21
-
-
Save liondancer/059c126dbca032a55a49294859941cff to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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