Last active
March 22, 2021 22:13
-
-
Save BriceShatzer/6713f4eb3f77aa07325a439b1509bb08 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
// - Write an example of a test case to make sure it works | |
// You have a set of expensive javascript asynchronous tasks to run, e.g. you need to make 10,000 ajax requests. | |
// You need a function that takes a set of tasks, and a concurrency limit (e.g. "5 tasks at a time") and runs the tasks until all are complete | |
// - Design the interface for this function, accounting for ease of use, reusability, error handling, and testing | |
// - Implement out the function | |
// - Write an example of a test case to make sure it works | |
// - What would you do to make it production ready if you had a week to work on it? | |
function runSet (arrOfFunctions){ | |
let resultsArr = []; | |
let currentlyRunningCount; | |
let allDone = [] | |
//let allDone = new Promise(resolve => { | |
// do some stuff | |
arrOfFunctions.forEach( (func,i)=>{ | |
const prom = new Promise ((resolve)=>{ | |
runOrWait(func,i); | |
function runOrWait (func,i){ | |
if(currentlyRunningCount>5) { | |
//wait and check letter; | |
setTimeout(200,()=>runOrWait(func,i)); | |
} else { | |
currentlyRunningCount++ | |
func.then((res)=>{ | |
//handle breaks | |
resultsArr.splice(i,0,res); | |
currentlyRunningCount--; | |
resolve(); | |
}); | |
} | |
} | |
} | |
allDone.push(prom) | |
}); | |
return Promise.all([...allDone]).then(()=>{ | |
return resultsArr | |
}) | |
// resolve(); | |
// }) | |
// return resultsArr; | |
// Promise.all( | |
// [funcA,FuncB] | |
// ).then(results) | |
// [a,b,c,d,e,f,g,] | |
} | |
// const resultsArr = ()=>funSet([ | |
// funcA, | |
// funcB, | |
// ]); |
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
// You have a set of expensive javascript asynchronous tasks to run, e.g. you need to make 10,000 ajax requests. | |
// You need a function that takes a set of tasks, and a concurrency limit (e.g. "5 tasks at a time") and runs the tasks until all are complete | |
// - Design the interface for this function, accounting for ease of use, reusability, error handling, and testing | |
// - Implement out the function | |
// - Write an example of a test case to make sure it works | |
// - What would you do to make it production ready if you had a week to work on it? | |
<html> | |
<script> | |
</script> | |
<body>Hello</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment