Coroutines Page

Coroutines



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

* What programming languages support Coroutines. Answer in MediaWiki syntax with the URL of the official documentation for each language reference.


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.
* Official Documentation: [https://docs.python.org/3/library/asyncio-task.html Python asyncio documentation]

Kotlin


Kotlin offers first-class support for coroutines, facilitating asynchronous programming and more.
* Official Documentation: [https://kotlinlang.org/docs/reference/coroutines-overview.html Kotlin Coroutines documentation]

Lua


Lua has coroutines as part of its standard library, allowing for cooperative multitasking in Lua programs.
* Official Documentation: [https://www.lua.org/pil/9.html Lua 5.1 Reference Manual: Coroutines]

C#


C# supports coroutines in the Unity game development engine through its MonoBehaviour framework, using the `yield` keyword.
* Unity Documentation: [https://docs.unity3d.com/Manual/Coroutines.html Unity: Coroutines]

JavaScript


While JavaScript does not have native coroutines, it uses async/await syntax, which can be considered similar to coroutines, for asynchronous operations.
* Official Documentation: [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function MDN Web Docs: async function]

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.
* Official Documentation: [https://golang.org/doc/effective_go#goroutines Go: Effective Go - Goroutines]

Rust


Rust supports asynchronous programming with async/await, which can be used in a similar way to coroutines for non-blocking I/O operations.
* Official Documentation: [https://rust-lang.github.io/async-book/ Rust Async Book]

Swift


Swift introduced structured concurrency with Swift 5.5, including async/await syntax for asynchronous programming, similar to coroutines.
* Official Documentation: [https://docs.swift.org/swift-book/LanguageGuide/Concurrency.html Swift: Concurrency]

Scala


Scala supports coroutines through libraries, such as Scala Async, which provides non-blocking asynchronous programming.
* Library Documentation: [https://github.com/scala/scala-async Scala Async on GitHub]

PHP


PHP offers coroutines through the Swoole extension, enabling asynchronous and concurrent programming for PHP applications.
* Swoole Documentation: [https://www.swoole.co.uk/docs/modules/swoole-coroutine Swoole Coroutine]

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 multitasking|cooperative tasks, exception handling|exceptions, event loops, iterators, lazy evaluation|infinite lists and pipeline (software)|pipes.

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



{{wp>Coroutine}}

{{navbar_coroutines]]}
navbar_coroutines

{{navbar_async}}

{{navbar_concurrency}}

{{navbar_footer}}