JSFiddle - React, Tailwind, and code Playground

HTML

<button>I will fire 4 times, and wait for 1 second after that</button>

JavaScript

var delay = ( function () {
    	var ticker = null;
    	var invokedCounter = 0
    
    	return function( callback, ms, delayAfter ) {
    		if ( typeof delayAfter === "number" && delayAfter > 0 && delayAfter === invokedCounter ) {
	    		if ( ticker !== null ) {
	    			clearTimeout( ticker )
	    		}
	    
	    		ticker = setTimeout(callback, ms)
    	    } else {
    	    	invokedCounter++
    	    	callback()
    	    }
    	}
    } () )

    $(document).ready(function () {
        // Pass delay two parameters, the first one is the callback
        // You want to delay, the second is the time in milliseconds to wait
        $("button").on("click", function () {
            delay(function () {
                alert("here I am")
            }, 1000, 4)
        });
    });