const func = () => {
return new Promise((resolve, reject)=>{
let key = setTimeout(reject, 30000, 'timeout Promise');
// Some action asynchronously for the result of the promis
removeTimeout(key);
resolve(data);
});
};
conf func = async function () {
try {
setTimeout((message)=>{
throw new Error(message);
} , 30000, 'timeout Promise');
// our asynchronous request using await
return result;
} catch (e) {
// something running
return await Promise.reject(e);
// Alternative variant of Dimitri:
throw e;
}
};
func().tnen(console.log).catch(console.error);
Find more questions by tags JavaScriptNode.js
to serietitel the result of the async function throw enough
in the same way if not intercepted reject from await - this is equivalent to throw
throw inside a timeout would work on a different thread of execution (different iteration of the event loop) and therefore thrown out in the overall trace, try-catch does not intercept it
PS can you take my Libu x-promise and use the timeout
https://github.com/bingo347/x-promise/wiki/.timeout() - kara commented on August 19th 19 at 22:45
(async function test(){
setTimeout(()=>{
throw new Error('TEST ERROR');
}, 1000);
})().then(resp=>{console.log('then: ', resp)}).catch(resp=>{console.error('catch: ', resp)});
which led to the wrong result that I expected at this potamanov on https://developer.mozilla.org/en-US/docs/Web/JavaS... reject the idea, but Yes, catch enough to raise the error above using throw
For the link to the code thanks. wonder, I will say however, that Sachs I prefer using native tools. - reyna.Greenholt commented on August 19th 19 at 22:48