Last active
November 18, 2021 12:05
-
-
Save wermarter/fbd29ea5ab5b969d3a659bde5273bc62 to your computer and use it in GitHub Desktop.
Timeout function execution
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
const timeout_function = async (func, timeLimit) => { | |
return new Promise((resolve, reject) => { | |
const timer = setTimeout(() => { | |
console.log("Timeout reached"); | |
reject(null); | |
}, timeLimit); | |
const result = func(); | |
resolve(result); | |
clearTimeout(timer); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment