Why does C++’s async/await not need an event loop?

Python and JavaScript don’t do CPU threads (well, Python can do threads, but that’s not relevant here, because Python’s thread stuff isn’t inherently await-able). So they fake threading with “event loops”. C++ is a low-level language that knows what CPU threads are and expects to make use of them. As such, when you co_await on … Read more

How to call suspend function from Service Android?

You can create your own CoroutineScope with a SupervisorJob that you can cancel in the onDestroy() method. The coroutines created with this scope will live as long as your Service is being used. Once onDestroy() of your service is called, all coroutines started with this scope will be cancelled. class YourService : Service() { private … Read more

How to execute two “aggregate” functions (like sum) concurrently, feeding them from the same iterator?

Let’s consider how to apply two aggregate functions to the same iterator, which we can only exhaust once. The initial attempt (which hardcodes sum and max for brevity, but is trivially generalizable to an arbitrary number of aggregate functions) might look like this: def max_and_sum_buffer(it): content = list(it) p = sum(content) m = max(content) return … Read more

How to unit test Kotlin suspending functions

I’ve found out that it’s because of a CoroutineDispatcher. I used to mock UI context with EmptyCoroutineContext. Switching to Unconfined has solved the problem Update 02.04.20 The name of the question suggests that there’ll be an exhaustive explanation how to unit test a suspending function. So let me explain a bit more. The main problem … Read more

What are the mechanics of coroutines in C++20?

N4775 outlines the proposal for coroutines for C++20. It introduces an number of different ideas. The following is from my blog at https://dwcomputersolutions.net . More info can be found in my other posts. Before we examine our whole Hello World coroutine program, go through the various parts step-by-step. These include: The coroutine Promise The coroutine … Read more

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