Can “experimental” Kotlin coroutines be used in production?

UPDATE: Kotlin coroutines are no longer experimental as of Kotlin 1.3. Kotlin coroutines can and should be used in production. That was the chief reason to officially release them in Kotlin 1.1. Having released them, the JetBrains team had committed to maintain backwards compatibility with respect to any changes that are introduced to them in … Read more

How do stackless coroutines differ from stackful coroutines?

First, thank you for taking a look at CO2 🙂 The Boost.Coroutine doc describes the advantage of stackful coroutine well: stackfulness In contrast to a stackless coroutine a stackful coroutine can be suspended from within a nested stackframe. Execution resumes at exactly the same point in the code where it was suspended before. With a … Read more

GlobalScope vs CoroutineScope vs lifecycleScope

First, let’s start with definitions to make it clear. If you need a tutorial or playground for Coroutines and Coroutines Flow you can check out this tutorial/playground i created. Scope is object you use to launch coroutines that only contains one object which is CoroutineContext public interface CoroutineScope { /** * The context of this … Read more

asyncio.ensure_future vs. BaseEventLoop.create_task vs. simple coroutine?

Actual info: Starting from Python 3.7 asyncio.create_task(coro) high-level function was added for this purpose. You should use it instead other ways of creating tasks from coroutimes. However if you need to create task from arbitrary awaitable, you should use asyncio.ensure_future(obj). Old info: ensure_future vs create_task ensure_future is a method to create Task from coroutine. It … Read more

What are coroutines in C++20?

At an abstract level, Coroutines split the idea of having an execution state off of the idea of having a thread of execution. SIMD (single instruction multiple data) has multiple “threads of execution” but only one execution state (it just works on multiple data). Arguably parallel algorithms are a bit like this, in that you … Read more

What is a coroutine?

Coroutines and concurrency are largely orthogonal. Coroutines are a general control structure whereby flow control is cooperatively passed between two different routines without returning. The ‘yield’ statement in Python is a good example. It creates a coroutine. When the ‘yield ‘ is encountered the current state of the function is saved and control is returned … Read more

Greenlet Vs. Threads

Greenlets provide concurrency but not parallelism. Concurrency is when code can run independently of other code. Parallelism is the execution of concurrent code simultaneously. Parallelism is particularly useful when there’s a lot of work to be done in userspace, and that’s typically CPU-heavy stuff. Concurrency is useful for breaking apart problems, enabling different parts to … Read more

Coroutine vs Continuation vs Generator

I’ll start with generators, seeing as they’re the simplest case. As @zvolkov mentioned, they’re functions/objects that can be repeatedly called without returning, but when called will return (yield) a value and then suspend their execution. When they’re called again, they will start up from where they last suspended execution and do their thing again. A … Read more