Skip to content

Instantly share code, notes, and snippets.

@cld-santos
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cld-santos/11006832 to your computer and use it in GitHub Desktop.
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.
<!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>
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