Created
January 30, 2017 02:41
-
-
Save liondancer/2e30fd0b06e31285ec4777170699b528 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
const whileHeapList = () => { | |
var heapNode = null; | |
var currTimestamp = null; | |
var nextMinTimestamp = null; | |
if (minheap.heapList.length) { | |
heapNode = minheap.popMin(); | |
currTimestamp = heapNode['ts']; | |
printer.print(heapNode.data); | |
nextMinTimestamp = minheap.getPeakTimestamp(); | |
const whileCurrTimestampLTENextMinTimestamp = () => { | |
if (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 | |
}); | |
} | |
setTimeout(whileHeapList ,0); | |
} | |
}).catch(err => { | |
console.log(err); | |
console.log(err.stack); | |
}); | |
// continue iteration | |
setTimeout(whileCurrTimestampLTENextMinTimestamp, 0); | |
} | |
}; | |
// first iteration of whileCurrTimestampLTENextMinTimestamp | |
whileCurrTimestampLTENextMinTimestamp(); | |
// continue iteration | |
setTimeout(whileHeapList, 0) | |
} else { | |
console.log('Drained: ' + heapNode['source']); | |
heapNode = minheap.popMin(); | |
printer.print(heapNode.data); | |
currTimestamp = heapNode['ts']; | |
if (minheap.heapList.length) { | |
nextMinTimestamp = minheap.getPeakTimestamp(); | |
} else { | |
const whileTrue = () => { | |
logSources[heapNode['source']].popAsync().then(m => { | |
if (m) { | |
printer.print(m); | |
setTimeout(whileTrue, 0); | |
} else { | |
console.log('Drained: ' + heapNode['source']); | |
} | |
}); | |
}; | |
// first iteration of whileTrue | |
setTimeout(whileTrue, 0); | |
} | |
} | |
}; | |
// first iteration of whileHeapList | |
whileHeapList(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment