I get an interview question. I abstract it as below: If you call setInterval, and the callback (or parameter) function is blocked, what should you do?
setInterval( () => {
someFunction(); // ? What should I do if someFunction is blocked
}, 100);
The original interview question has two sections.
- The first one is, that you simulate setInterval with setTimeout.
- The second one is, that if callback (or parameter / ? the term I used is right) function is blocked, how do you do with the problem?
The first one, there is my solution:
function setInterval(func, period){
setTimeout( () => {
func(); // what if func is blocked, how do you deal with it?
setInterval(func, period);
}, period);
}
setInterval( () => {
console.log("There is simulated setInterval ... ");
}, 100);
To the second question, How do I solve it?
Here is: Js Bin