https://github.com/dokar3/mini-coroutines Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions For + Enterprise + Teams + Startups + Education By Solution + CI/CD & Automation + DevOps + DevSecOps Resources + Learning Pathways + White papers, Ebooks, Webinars + Customer Stories + Partners * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Search [ ] Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. [ ] [ ] Include my email address so I can be contacted Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly Name [ ] Query [ ] To see all available qualifiers, see our documentation. Cancel Create saved search Sign in Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} dokar3 / mini-coroutines Public * Notifications * Fork 0 * Star 27 Kotlin coroutines runtime in 400 lines 27 stars 0 forks Activity Star Notifications * Code * Issues 1 * Pull requests 0 * Actions * Projects 0 * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Security * Insights dokar3/mini-coroutines This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. main Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 1 branch 0 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/d] Use Git or checkout with SVN using the web URL. [gh repo clone dokar3] Work fast with our official CLI. Learn more about the CLI. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @dokar3 dokar3 Merge pull request #5 from dokar3/renovate/ org.gradle.toolchains.fooj... ... 0c5883f Nov 16, 2023 Merge pull request #5 from dokar3/renovate/ org.gradle.toolchains.fooj... ...ay-resolver-convention-0.x Update plugin org.gradle.toolchains.foojay-resolver-convention to v0.7.0 0c5883f Git stats * 9 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .idea Initial commit November 16, 2023 19:37 coroutines Update junit5 monorepo to v5.10.1 November 16, 2023 13:10 examples Initial commit November 16, 2023 19:37 gradle/wrapper Update dependency gradle to v8.4 November 16, 2023 13:10 .gitignore Initial commit November 16, 2023 19:37 README.md Initial commit November 16, 2023 19:37 build.gradle.kts Initial commit November 16, 2023 19:37 gradle.properties Initial commit November 16, 2023 19:37 gradlew Update dependency gradle to v8.4 November 16, 2023 13:10 gradlew.bat Update dependency gradle to v8.4 November 16, 2023 13:10 renovate.json Add renovate.json November 16, 2023 13:08 settings.gradle.kts Update plugin org.gradle.toolchains.foojay-resolver-convention to v0.7.0 November 16, 2023 15:56 View code Mini Coroutines How minimal? What's present? What's missing? Can I use it in my project? Examples README.md Mini Coroutines A minimal Kotlin/JVM Coroutines runtime. How minimal? ======= .kt Line Counter ====== Lines: 490 Non-empty lines: 407 What's present? * runBlocking {} Run coroutines in a coroutine scope. It starts an event loop internally * launch {} Launch a new coroutine. It returns a task * await(), cancel() Control launched coroutine tasks * withContext {} Switch to another coroutine context. It just calls launch and awaits the result * delay() Delay the coroutine execution. It reschedules the current task to the event queue * Dispatchers Decide the thread(pool) to run coroutine (Main dispatcher is not supported yet) What's missing? * Flows and channels * Exception handler * Parent-children job support * Concurrency primitives (Mutex, Semaphore, etc.) * Start strategies * Testing mechanisms * ... Can I use it in my project? NO. It's for learning purposes, it lacks features, can be buggy, has no tests, and isn't performant. So don't use it for other purposes. Examples // Launch 100K Coroutines fun main(): Unit = runBlocking { val count = 100_000 val done = AtomicInteger(0) val millis = measureTimeMillis { val tasks = List(count) { launch { delay(3000) done.incrementAndGet() } } tasks.forEach { it.await() } } check(done.get() == count) println("$count coroutines finished in ${millis}ms") } About Kotlin coroutines runtime in 400 lines Resources Readme Activity Stars 27 stars Watchers 2 watching Forks 0 forks Report repository Releases No releases published Contributors 2 * @dokar3 dokar3 * @renovate[bot] renovate[bot] Languages * Kotlin 100.0% Footer (c) 2023 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time.