async-await

Different HTTP calls, await same Task

北慕城南 提交于 2021-02-19 03:14:17
问题 I have a Task which starts a win process, which generates file if its not created yet and returns it. The problem is that the action is called more than once. To be more precisely its src attribute of a <track> element. I have ConcurrentDictionary<Guid, Task<string>> which keeps track of for which Id a process is currently running public async Task<string> GenerateVTTFile(Guid Id) { if (_currentGenerators.TryGetValue(id, out Task<string> task)) { return await task; // problem is here? } var t

Different HTTP calls, await same Task

守給你的承諾、 提交于 2021-02-19 03:08:39
问题 I have a Task which starts a win process, which generates file if its not created yet and returns it. The problem is that the action is called more than once. To be more precisely its src attribute of a <track> element. I have ConcurrentDictionary<Guid, Task<string>> which keeps track of for which Id a process is currently running public async Task<string> GenerateVTTFile(Guid Id) { if (_currentGenerators.TryGetValue(id, out Task<string> task)) { return await task; // problem is here? } var t

Why do I have to put async keyword to functions which have await keywords?

浪尽此生 提交于 2021-02-18 22:33:06
问题 I just want to wait for a process to finish, not want to make the function asynchronous. See the below code. I had to make getUserList asynchronous because there was an await keyword in the function. Therefore I also had to write like "await UsersService.getUserList" to execute the method and also I had to make the parent function asynchronous. That's not what I want to do. import xr from 'xr' //a package for http requests class UsersService { static async getUserList() { const res = await xr

Why do I have to put async keyword to functions which have await keywords?

风流意气都作罢 提交于 2021-02-18 22:30:27
问题 I just want to wait for a process to finish, not want to make the function asynchronous. See the below code. I had to make getUserList asynchronous because there was an await keyword in the function. Therefore I also had to write like "await UsersService.getUserList" to execute the method and also I had to make the parent function asynchronous. That's not what I want to do. import xr from 'xr' //a package for http requests class UsersService { static async getUserList() { const res = await xr

Handling multiple exceptions from async parallel tasks

丶灬走出姿态 提交于 2021-02-18 22:13:27
问题 Problem Several tasks are run in parallel, and all, none, or any of them might throw exceptions. When all the tasks have finalized, all the exceptions that might have happened must be reported (via log, email, console output.... whatever). Expected behavior I can build all the tasks via linq with async lambdas, and then await for them running in parallel with Task.WhenAll(tasks) . Then I can catch an AggregateException and report each of the individual inner exceptions. Actual behavior An

Handling multiple exceptions from async parallel tasks

社会主义新天地 提交于 2021-02-18 22:13:05
问题 Problem Several tasks are run in parallel, and all, none, or any of them might throw exceptions. When all the tasks have finalized, all the exceptions that might have happened must be reported (via log, email, console output.... whatever). Expected behavior I can build all the tasks via linq with async lambdas, and then await for them running in parallel with Task.WhenAll(tasks) . Then I can catch an AggregateException and report each of the individual inner exceptions. Actual behavior An

Write to S3 bucket using Async/Await in AWS Lambda

允我心安 提交于 2021-02-18 21:12:07
问题 I have been using the code below (which I have now added await to) to send files to S3. It has worked fine with my lambda code but as I move to transfer larger files like MP4 I feel I need async/await. How can I fully convert this to async/await? exports.handler = async (event, context, callback) => { ... // Copy data to a variable to enable write to S3 Bucket var result = response.audioContent; console.log('Result contents ', result); // Set S3 bucket details and put MP3 file into S3 bucket

Handling network errors with Puppeteer

可紊 提交于 2021-02-18 08:11:20
问题 Has anyone ever tried to handle network connexion errors with Puppeteer ? I tried by launching a random page and checking if I receive no errors until it works ( this try is in a for loop ) : try{ responseAwait = await page1.goto('https://www.residentadvisor.net/dj.aspx?country=01') } catch (err) { console.log('Page load fail : '+ err) if (err == 'Error: net::ERR_INTERNET_DISCONNECTED' || err == 'Error: net::ERR_NETWORK_CHANGED' || err == 'Error: net::ERR_NAME_NOT_RESOLVED'){ let

Correct mental model for a Javascript async function's 'await': generator's 'yield' vs. 'promise.then()'?

早过忘川 提交于 2021-02-18 07:43:12
问题 Which of a generator's yield vs. promise.then() is a more* correct mental model for understanding 'await'? Property comparison, inferred by stepping through the snippet below with a debugger: await: await does not pause/suspend the running async function’s execution. (The running async function ‘runs to completion’, returning a pending promise when the interpreter hits the 1st await. It’s then immediately removed from the call stack.) await waits for the promise to settle. await expression

What is the meaning of the `async` keyword?

安稳与你 提交于 2021-02-17 07:18:34
问题 I have been reading up on async/await in node.js. I have learnt that the await keyword waits for a promise to be resolved, or throws an exception if it was rejected. I have also learnt that every function that wants to use await needs to be marked async . However, what does it mean for a function to be marked async ? All the resources and blog posts I was able to find seem to explain await in great detail, but ignore the concept of an async function, or briefly gloss over it. For instance,