Created
January 30, 2017 02:44
-
-
Save liondancer/4426e1f8cbeeec0c69466ce89a6c9732 to your computer and use it in GitHub Desktop.
code I am trying to fix
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 wait = fnc => new Promise(fnc => setTimeout(fnc, 0)); |
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