You cannot make a truly custom asynchronous function. You’ll eventually have to leverage on a technology provided natively, such as:
setIntervalsetTimeoutrequestAnimationFrameXMLHttpRequestWebSocketWorker- Some HTML5 APIs such as the File API, Web Database API
- Technologies that support
onload - … many others
In fact, for the animation jQuery uses setInterval.