Coroutines with Higher Order Functions
Dimitri Racordon

TL;DR
This paper presents a simple method to implement coroutine-like components using higher order functions in any language that supports or can emulate them, demonstrated with JavaScript examples.
Contribution
It introduces a straightforward approach to emulate coroutines using higher order functions, enabling their use in languages lacking native coroutine support.
Findings
Effective coroutine emulation in JavaScript
Minimal code complexity for coroutine implementation
Broad applicability to languages with higher order functions
Abstract
Coroutines are non-preemptive concurrent subroutines that, unlike preemptive threads, voluntarily transfer control between each others. Introduced in the 60s before loosing in popularity in the 80s, they have seen a regain of interest in recent years, thanks to how elegantly they can solve numerous algorithmic problems. Unfortunately, some mainstream languages still lack support for coroutines, hence requiring either the use of non-standard interpreter/compilers, or elaborate hacks in thrid-party libraries. In this short paper, we propose a very simple way to implement coroutine-like components on the top of any language that support or can emulate higher order functions. We accompany our explanations with a handful of examples in JavaScript.
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsParallel Computing and Optimization Techniques · Logic, programming, and type systems · Algorithms and Data Compression
