Last active
June 15, 2021 12:31
-
-
Save bjangid20/5a9f62cc9ce358c0334ccac30bbaa4f6 to your computer and use it in GitHub Desktop.
Execute last async call only and ignore other calls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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