coroutines

Coroutines

Return to Futures, Promises, Asynchronous Programming, Asynchrony, Asynchronous Programming Fundamentals

Coroutines are programming constructs that generalize subroutines for non-preemptive multitasking, allowing execution to be suspended and resumed. They are used extensively in asynchronous programming to simplify the writing of non-blocking code and to efficiently handle concurrency. Below is a list of programming languages that support coroutines, formatted in MediaWiki syntax, including the URL of the official documentation for each language's coroutine support.

Python

Python supports coroutines through its `asyncio` library, enabling asynchronous I/O operations.

Kotlin

Kotlin offers first-class support for coroutines, facilitating asynchronous programming and more.

Lua

Lua has coroutines as part of its standard library, allowing for cooperative multitasking in Lua programs.

C#

C# supports coroutines in the Unity game development engine through its MonoBehaviour framework, using the `yield` keyword.

JavaScript

While JavaScript does not have native coroutines, it uses async/await syntax, which can be considered similar to coroutines, for asynchronous operations.

Go

Go uses goroutines, which are similar to coroutines but are more lightweight and managed by the Go runtime. They are used for concurrent tasks.

Rust

Rust supports asynchronous programming with async/await, which can be used in a similar way to coroutines for non-blocking I/O operations.

Swift

Swift introduced structured concurrency with Swift 5.5, including async/await syntax for asynchronous programming, similar to coroutines.

Scala

Scala supports coroutines through libraries, such as Scala Async, which provides non-blocking asynchronous programming.

PHP

PHP offers coroutines through the Swoole extension, enabling asynchronous and concurrent programming for PHP applications.

Each of these languages or environments provides support for coroutines or similar constructs, enabling developers to write efficient, non-blocking, and concurrent code. The official documentation for each offers in-depth guides on how to effectively use coroutines or their equivalents within their respective programming paradigms.


Coroutines are computer program components that generalize subroutines for non-preemptive multitasking, by allowing execution to be suspended and resumed. Coroutines are well-suited for implementing familiar program components such as cooperative tasks, exceptions, event loops, iterators, infinite lists and pipes.

According to Donald Knuth, Melvin Conway coined the term coroutine in 1958 when he applied it to the construction of an assembly program. The first published explanation of the coroutine appeared later, in 1963.

Snippet from Wikipedia: Coroutine

Coroutines are computer program components that allow execution to be suspended and resumed, generalizing subroutines for cooperative multitasking. Coroutines are well-suited for implementing familiar program components such as cooperative tasks, exceptions, event loops, iterators, infinite lists and pipes.

They have been described as "functions whose execution you can pause".

Melvin Conway coined the term coroutine in 1958 when he applied it to the construction of an assembly program. The first published explanation of the coroutine appeared later, in 1963.


© 1994 - 2024 Cloud Monk Losang Jinpa or Fair Use. Disclaimers

SYI LU SENG E MU CHYWE YE. NAN. WEI LA YE. WEI LA YE. SA WA HE.


Concurrency: Concurrency Programming Best Practices, Concurrent Programming Fundamentals, Parallel Programming Fundamentals, Asynchronous I/O, Asynchronous programming (Async programming, Asynchronous flow control, Async / await), Asymmetric Transfer, Akka, Atomics, Busy waiting, Channels, Concurrent, Concurrent system design, Concurrency control (Concurrency control algorithms‎, Concurrency control in databases, Atomicity (programming), Distributed concurrency control, Data synchronization), Concurrency pattern, Concurrent computing, Concurrency primitives, Concurrency problems, Concurrent programming, Concurrent algorithms, Concurrent programming languages, Concurrent programming libraries‎, Java Continuations, Coroutines, Critical section, Deadlocks, Decomposition, Dining philosophers problem, Event (synchronization primitive), Exclusive or, Execution model (Parallel execution model), Fibers, Futures, Inter-process communication, Linearizability, Lock (computer science), Message passing, Monitor (synchronization), Computer multitasking (Context switch, Pre-emptive multitasking - Preemption (computing), Cooperative multitasking - Non-preemptive multitasking), Multi-threaded programming, Multi-core programming, Multi-threaded, Mutual exclusion, Mutually exclusive events, Mutex, Non-blocking algorithm (Lock-free), Parallel programming, Parallel computing, Process (computing), Process state, Producer-consumer problem (Bounded-buffer problem), Project Loom, Promises, Race conditions, Read-copy update (RCU), Readers–writer lock, Readers–writers problem, Recursive locks, Reducers, Reentrant mutex, Scheduling (computing)‎, Semaphore (programming), Seqlock (Sequence lock), Serializability, Shared resource, Sleeping barber problem, Spinlock, Synchronization (computer science), System resource, Thread (computing), Tuple space, Volatile (computer programming), Yield (multithreading), Concurrency bibliography, Manning Concurrency Async Parallel Programming Series, Concurrency glossary, Awesome Concurrency, Concurrency topics, Functional programming. (navbar_concurrency - see also navbar_async, navbar_python_concurrency, navbar_golang_concurrency, navbar_java_concurrency)

coroutines.txt · Last modified: 2024/04/28 03:12 by 127.0.0.1