Last active
August 29, 2015 14:00
-
-
Save cld-santos/11006832 to your computer and use it in GitHub Desktop.
This samples show how to enable a pool of requests made by multiples clicks on a html button for example.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="Multiple clicks trigger a pool of executed functions" /> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<input id="txtMsg" type="text"/> | |
<button id="btnRun">Add to run</button></br> | |
<button id="btnStop">Stop</button> | |
<div>add a message and click a lot times on the add button </div> | |
</body> | |
</html> |
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
var listRuns = [], | |
ind = 0; | |
var run = function(value){ | |
console.log(value); | |
}; | |
var runAll = function(){ | |
console.log('called'); | |
if (listRuns.length>ind){ | |
listRuns[ind](); | |
ind++; | |
} | |
}; | |
$('#btnRun').click(function(){ | |
var message = document.getElementById("txtMsg").value; | |
listRuns.push(function(){ | |
run(message); | |
}); | |
}); | |
var idInterval = setInterval(function(){ | |
runAll(); | |
},1000); | |
$('#btnStop').click(function(){ | |
window.clearInterval(idInterval); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment