Created
November 22, 2019 14:25
-
-
Save arnogues/c3c2a5e570b607b52b1e4c2731c54240 to your computer and use it in GitHub Desktop.
Set actions on any project, (useful for debugging)
This file contains 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
function queue(list, lastValue) { | |
var item = list[0]; | |
if (!list.length) { | |
console.log("Queue debug end"); | |
return; | |
} | |
switch (typeof item) { | |
case "number": | |
setTimeout(function() { | |
queue.call(this, list.slice(1)); | |
}, item); | |
break; | |
case "function": | |
var counter = 0; | |
var fnSearch = function() { | |
var result = item(lastValue); | |
if (result === undefined || result !== null) { | |
queue.call(this, list.slice(1), result); | |
} else { | |
if (counter < 50) { | |
counter++; | |
setTimeout(function() { | |
fnSearch(); | |
}, 50); | |
} else { | |
console.error( | |
"function error, element not found after", | |
(counter + 1) * 50, | |
"milliseconds" | |
); | |
} | |
} | |
}; | |
fnSearch(); | |
break; | |
default: | |
console.error("Item in the list is not a number or function"); | |
} | |
} | |
queue([ | |
300, | |
function() { | |
return document.body; | |
}, | |
function(result) { | |
result.style.background = "red"; | |
} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment