I want to suspend execution of a statement if it takes more than certain time. Help me please to achieve this?
In the below given sample snippet of code, if the statement const result = await curly.get('www.google.com');
takes more than 2 seconds of time to complete execution I want to suspend execution of the statement and throw an exception.
const { curly } = require('node-libcurl');
exports.curlFetch = async () => {
try {
const result = await curly.get('www.google.com');
return result;
} catch (err) {
console.error('----------ERRORR OCCURRED----------', err);
throw err;
}
}