As for the async feature to make a "reject" by timeout?

Hi all. Live example using promis:
const func = () => {
 return new Promise((resolve, reject)=>{
 let key = setTimeout(reject, 30000, 'timeout Promise');
 // Some action asynchronously for the result of the promis

Now suppose eating takaya same situation, but the description goes through the async function
How you can implement similar in design async?
August 19th 19 at 22:40
1 answer
August 19th 19 at 22:42
He found himself rewriting in async style:
conf func = async function () {
 try {
 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;

return await - the excess just return
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 - kara commented on August 19th 19 at 22:45
: thank you on account of exit through a throw, checked, Yes indeed you can do it, only when I test this option, I did
(async function test(){
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 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

Find more questions by tags JavaScriptNode.js