Understanding dispatch_async

I have question around this code dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSData* data = [NSData dataWithContentsOfURL: kLatestKivaLoansURL]; [self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES]; }); The first parameter of this code is dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) Are we asking this code to perform serial tasks on global queue whose definition itself is that it returns global concurrent queue of a given … Read more

Difference between CompletableFuture, Future and RxJava’s Observable

I would like to know the difference between CompletableFuture,Future and Observable RxJava. What I know is all are asynchronous but Future.get() blocks the thread CompletableFuture gives the callback methods RxJava Observable — similar to CompletableFuture with other benefits(not sure) For example: if client needs to make multiple service calls and when we use Futures (Java) … Read more

Calling async method synchronously

I have an async method: public async Task<string> GenerateCodeAsync() { string code = await GenerateCodeService.GenerateCodeAsync(); return code; } I need to call this method from a synchronous method. How can I do this without having to duplicate the GenerateCodeAsync method in order for this to work synchronously? Update Yet no reasonable solution found. However, I … Read more

Async await in linq select

I need to modify an existing program and it contains following code: var inputs = events.Select(async ev => await ProcessEventAsync(ev)) .Select(t => t.Result) .Where(i => i != null) .ToList(); But this seems very weird to me, first of all the use of async and awaitin the select. According to this answer by Stephen Cleary I … Read more

Callback after all asynchronous forEach callbacks are completed

As the title suggests. How do I do this? I want to call whenAllDone() after the forEach-loop has gone through each element and done some asynchronous processing. [1, 2, 3].forEach( function(item, index, array, done) { asyncFunction(item, function itemDone() { console.log(item + ” done”); done(); }); }, function allDone() { console.log(“All done”); whenAllDone(); } ); Possible … Read more

Catch an exception thrown by an async void method

Using the async CTP from Microsoft for .NET, is it possible to catch an exception thrown by an async method in the calling method? public async void Foo() { var x = await DoSomethingAsync(); /* Handle the result, but sometimes an exception might be thrown. For example, DoSomethingAsync gets data from the network and the … Read more

If async-await doesn’t create any additional threads, then how does it make applications responsive?

Time and time again, I see it said that using async–await doesn’t create any additional threads. That doesn’t make sense because the only ways that a computer can appear to be doing more than 1 thing at a time is Actually doing more than 1 thing at a time (executing in parallel, making use of … Read more