Skip to content

Instantly share code, notes, and snippets.

@wermarter
Last active November 18, 2021 12:05
Show Gist options
  • Save wermarter/fbd29ea5ab5b969d3a659bde5273bc62 to your computer and use it in GitHub Desktop.
Save wermarter/fbd29ea5ab5b969d3a659bde5273bc62 to your computer and use it in GitHub Desktop.
Timeout function execution
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