Prevent a function from being fired too rapidly
<p>I have a function. It is being triggered from many other functions in the script. Sometimes very rapid and maybe almost simultaneously</p>

<p>How can I prevent it from being triggered too rapidly within short time? By setting a delay or timer of some sort? I want to minimize the database calls the function is making</p>

<p>But there should be no delay in the function if it's not needed.. Meaning: First call = no delay. All other calls = only delay if previous call was less than x seconds ago. 
And if the delay is set to let's say 5 seconds, the function should only wait 1 second if the previous call was made 4 seconds ago.. Hope you understand what I mean ;)</p>

<pre><code>function checkusers() {

    $.ajax({
        url: '/checkusers_in_db.php',
        type: 'POST'
    });

};
</code></pre>
