Created
May 16, 2023 09:31
-
-
Save Tribhuwan-Joshi/11b6cf273e2d2aadf6726d87b0a0e834 to your computer and use it in GitHub Desktop.
Promise Time Limit JS
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
/** | |
* @param {Function} fn | |
* @param {number} t | |
* @return {Function} | |
*/ | |
var timeLimit = function(fn, t) { | |
return async function(...args) { | |
return Promise.race([new Promise((res,rej)=>setTimeout(()=>rej("Time Limit Exceeded"),t)) , fn(...args) ]) | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment