Skip to content

Instantly share code, notes, and snippets.

@bjangid20
Last active June 15, 2021 12:31
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 bjangid20/5a9f62cc9ce358c0334ccac30bbaa4f6 to your computer and use it in GitHub Desktop.
Save bjangid20/5a9f62cc9ce358c0334ccac30bbaa4f6 to your computer and use it in GitHub Desktop.
Execute last async call only and ignore other calls
var clear;
function calling (param, time) {
clearTimeout(clear);
var promise = new Promise(function(resolve, reject) {
clear = setTimeout(() => resolve(param), time);
});
promise.then(r => console.log('Do whatever you want', r));
}
calling('him', 3000);
calling('gup', 2000);
calling('ravi', 1000);
calling('God', 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment