Difference between CompletableFuture, Future and RxJava’s Observable

Futures Futures were introduced in Java 5 (2004). They’re basically placeholders for a result of an operation that hasn’t finished yet. Once the operation finishes, the Future will contain that result. For example, an operation can be a Runnable or Callable instance that is submitted to an ExecutorService. The submitter of the operation can use … Read more

Why would one use Task over ValueTask in C#?

From the API docs (emphasis added): Methods may return an instance of this value type when it’s likely that the result of their operations will be available synchronously and when the method is expected to be invoked so frequently that the cost of allocating a new Task<TResult> for each call will be prohibitive. There are … Read more

Asyncio.gather vs asyncio.wait

Although similar in general cases (“run and get results for many tasks”), each function has some specific functionality for other cases: asyncio.gather() Returns a Future instance, allowing high level grouping of tasks: import asyncio from pprint import pprint import random async def coro(tag): print(“>”, tag) await asyncio.sleep(random.uniform(1, 3)) print(“<“, tag) return tag loop = asyncio.get_event_loop() … Read more

Callback after all asynchronous forEach callbacks are completed

Array.forEach does not provide this nicety (oh if it would) but there are several ways to accomplish what you want: Using a simple counter function callback () { console.log(‘all done’); } var itemsProcessed = 0; [1, 2, 3].forEach((item, index, array) => { asyncFunction(item, () => { itemsProcessed++; if(itemsProcessed === array.length) { callback(); } }); }); … Read more

What is the difference between concurrency, parallelism and asynchronous methods?

Concurrent and parallel are effectively the same principle as you correctly surmise, both are related to tasks being executed simultaneously although I would say that parallel tasks should be truly multitasking, executed “at the same time” whereas concurrent could mean that the tasks are sharing the execution thread while still appearing to be executing in … Read more

Async await in linq select

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 await in the select. According to this answer by Stephen Cleary I should be able to drop those. The call to Select is … Read more

Why use async and return await, when you can return Task directly?

There is one sneaky case when return in normal method and return await in async method behave differently: when combined with using (or, more generally, any return await in a try block). Consider these two versions of a method: Task<SomeResult> DoSomethingAsync() { using (var foo = new Foo()) { return foo.DoAnotherThingAsync(); } } async Task<SomeResult> … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)