Last active
February 17, 2019 04:24
-
-
Save j-quelly/ff65d1ed23d0c916f364258220cc060f 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
// files to queue | |
let filesToProcess = [ | |
'file1', | |
'file2', | |
'file3', | |
'file4', | |
'file5', | |
'file6', | |
'file7', | |
'file8', | |
'file9', | |
'file10', | |
]; | |
// simulated queue that runs after 500ms unless the queue is cleared by user | |
let queue = setInterval( | |
function () { | |
if (filesToProcess.length) { | |
// TODO: some actual compression happens here... | |
console.log(filesToProcess[0]); | |
filesToProcess.shift(); | |
} | |
}, | |
500 | |
); | |
function clearQueue() { | |
filesToProcess = []; | |
// this could be problematic if your users try again | |
// but you could always create a new interval | |
clearInterval(queue); | |
} | |
// simulate canceling the queue after 3 seconds | |
setTimeout(() => { | |
clearQueue(); | |
// may not need this I just want my process to end when prototyping with node | |
process.exit(); | |
}, 3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment