asynchronous

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

What's the recommended way to deal with leaked IAsyncDisposable instances?

夙愿已清 提交于 2021-02-18 22:31:31
问题 I've been familiarizing myself with some of the things (that are planned to be) added in C# 8 & .NET Core 3.0, and am unsure on the correct way to implement IAsyncDisposable (at time of writing, this link has literally no guidance). In particular, it is unclear to me what to do in the case when an instance isn't explicitly disposed - that is, it isn't wrapped in an async using(...) and .DisposeAsync() isn't explicitly called. My first thought was to do that same thing I'd do when implementing

Async/await vs Task.Run in C#

假装没事ソ 提交于 2021-02-18 12:16:25
问题 I am just new to this world of asynchronous stuff. Please bear with my lack of knowledge. It is said when a method encounters await ... " It tells the awaitable to run the remainder of the method when it completes, and then returns from the async method. " I did not get this part. So does it mean the method still keeps on running synchronously and waits till the awaitable returns and then proceeds with the rest of the method? If not please explain then why Task.Run is needed to run a method

Understanding async/await vs Wait in C# with “ContinueWith” behavior

泄露秘密 提交于 2021-02-18 10:46:06
问题 One method is a standard async method, like this one : private static async Task AutoRetryHandlerAsync_Worker(Func<Task<bool>> taskToRun,...) I have tested two implementations, one that use await and the other uses .Wait() The two implementations are not equal at all because the same tests are failing with the await version but not the Wait() one. The goal of this method is to "execute a Task returned by the input function, and retry by executing the same function until it works" (with

Understanding async/await vs Wait in C# with “ContinueWith” behavior

匆匆过客 提交于 2021-02-18 10:46:02
问题 One method is a standard async method, like this one : private static async Task AutoRetryHandlerAsync_Worker(Func<Task<bool>> taskToRun,...) I have tested two implementations, one that use await and the other uses .Wait() The two implementations are not equal at all because the same tests are failing with the await version but not the Wait() one. The goal of this method is to "execute a Task returned by the input function, and retry by executing the same function until it works" (with

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

File.Delete the process cannot access the file because it is being used by another process

混江龙づ霸主 提交于 2021-02-17 06:51:22
问题 public bool DownloadMp3File (DownloadedMp3 mp3) { WebClient client = new WebClient (); string filePath = ""; bool wasDownload = false; try { string song = mp3.SongName; filePath = @"mp3\" + song + ".mp3"; if (File.Exists (filePath)) { File.Delete (filePath); } DateTime tryCountNow = DateTime.Now; client = new WebClient (); client.DownloadFileAsync (new Uri (mp3.Url), filePath); client.DownloadProgressChanged += client_DownloadProgressChanged; client.DownloadFileCompleted += client

Java/Spring Processing Spring batch job requests asynchronously

为君一笑 提交于 2021-02-17 06:33:24
问题 Currently, I expose a rest endpoint in my application that kick of spring batch jobs. However, the requests are not scheduled asynchronously. Response is provided after job completes with batch status in the MyResponse object. @RestController @RequestMapping("/test") public class TestController { private MyProcessor processor; private RequestDataRepo repo; public TestController(final MyProcessor processor, final RequestDataRepo repo) { this.feedProcessor = feedProcessor; this.repo = repo; }

Can't assign a value to variable inside of closure Swift [duplicate]

冷暖自知 提交于 2021-02-17 06:24:08
问题 This question already has answers here : Returning data from async call in Swift function (11 answers) Closed 9 months ago . I'm trying to get current document count belongs to spesific user from Firebase. Whenever i try to assign count value to my variable in closure, value is always shown as nill. So that i did couple of research, as a result i figured out networking sometimes takes so long and it happens asynchronously. So if i'm not wrong due to asynchronous returning a value inside a