Timeout a function in Javascript
Here's one way that seems to work, you set a time to change a function-scoped variable and return out of the function when that changes.
function thisShouldTimeOut() {
var shouldIStopDoingThis = false
setTimeout(() => {
shouldIStopDoingThis = true
}, 2000)
for () { // some loopy stuff
if (shouldIStopDoingThis) {
return
}
}
}