{"id":15036254,"url":"https://github.com/ellpeck/coroutine","last_synced_at":"2025-04-09T23:22:01.681Z","repository":{"id":53052243,"uuid":"193248457","full_name":"Ellpeck/Coroutine","owner":"Ellpeck","description":"A simple implementation of Unity's Coroutines to be used for any C# project","archived":false,"fork":false,"pushed_at":"2023-02-23T18:11:40.000Z","size":73,"stargazers_count":39,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-24T01:11:51.882Z","etag":null,"topics":["coroutines","csharp-library","netcore","netframework","unity-coroutines"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/Coroutine","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ellpeck.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"Ellpeck","ko_fi":"Ellpeck"}},"created_at":"2019-06-22T15:20:49.000Z","updated_at":"2024-12-26T02:13:18.000Z","dependencies_parsed_at":"2024-09-24T20:40:58.879Z","dependency_job_id":null,"html_url":"https://github.com/Ellpeck/Coroutine","commit_stats":{"total_commits":79,"total_committers":3,"mean_commits":"26.333333333333332","dds":0.5063291139240507,"last_synced_commit":"7501ffaf9c02e6dd74dbb9aa2f2197f166f4960a"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ellpeck%2FCoroutine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ellpeck%2FCoroutine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ellpeck%2FCoroutine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ellpeck%2FCoroutine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ellpeck","download_url":"https://codeload.github.com/Ellpeck/Coroutine/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248126459,"owners_count":21051925,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coroutines","csharp-library","netcore","netframework","unity-coroutines"],"created_at":"2024-09-24T20:30:38.660Z","updated_at":"2025-04-09T23:22:01.664Z","avatar_url":"https://github.com/Ellpeck.png","language":"C#","funding_links":["https://github.com/sponsors/Ellpeck","https://ko-fi.com/Ellpeck"],"categories":[],"sub_categories":[],"readme":"![The Coroutine logo](https://raw.githubusercontent.com/Ellpeck/Coroutine/main/Logo.png)\n\n**Coroutine** is a simple implementation of Unity's Coroutines to be used for any C# project\n\n# Features\nCoroutine adds the ability to run coroutines. Coroutines are methods that run in parallel to the rest of the application through the use of an `Enumerator`. This allows for the coroutine to pause execution using the `yield return` statement.\n\nThere are two predefined ways to pause a coroutine:\n- Waiting for a certain amount of seconds to have passed\n- Waiting for a certain custom event to occur\n\nAdditionally, Coroutine provides the following features:\n- Creation of custom events to wait for\n- No multi-threading, which allows for any kind of process to be executed in a coroutine, including rendering\n- Thread-safety, which allows for coroutines to be started from different threads\n\n# How to Use\n## Setting up the CoroutineHandler\nThe `CoroutineHandler` is the place where coroutines get executed. For this to occur, the `Tick` method needs to be called continuously. The `Tick` method takes a single parameter which represents the amount of time since the last time it was called. It can either be called in your application's existing update loop or as follows.\n```cs\nvar lastTime = DateTime.Now;\nwhile (true) {\n    var currTime = DateTime.Now;\n    CoroutineHandler.Tick(currTime - lastTime);\n    lastTime = currTime;\n    Thread.Sleep(1);\n}\n```\n\n## Creating a Coroutine\nTo create a coroutine, simply create a method with the return type `IEnumerator\u003cWait\u003e`. Then, you can use `yield return` to cause the coroutine to wait at any point:\n```cs\nprivate static IEnumerator\u003cWait\u003e WaitSeconds() {\n    Console.WriteLine(\"First thing \" + DateTime.Now);\n    yield return new Wait(1);\n    Console.WriteLine(\"After 1 second \" + DateTime.Now);\n    yield return new Wait(5);\n    Console.WriteLine(\"After 5 seconds \" + DateTime.Now);\n    yield return new Wait(10);\n    Console.WriteLine(\"After 10 seconds \" + DateTime.Now);\n}\n```\n\n## Starting a Coroutine\nTo start a coroutine, simply call `Start`:\n```cs \nCoroutineHandler.Start(WaitSeconds());\n```\n\n## Using Events\nTo use an event, an `Event` instance first needs to be created. When not overriding any equality operators, only a single instance of each event should be used.\n```cs\nprivate static readonly Event TestEvent = new Event();\n```\n\nWaiting for an event in a coroutine works as follows:\n```cs\nprivate static IEnumerator\u003cWait\u003e WaitForTestEvent() {\n    yield return new Wait(TestEvent);\n    Console.WriteLine(\"Test event received\");\n}\n```\nOf course, having time-based waits and event-based waits in the same coroutine is also supported.\n\nTo actually cause the event to be raised, causing all currently waiting coroutines to be continued, simply call `RaiseEvent`:\n```cs\nCoroutineHandler.RaiseEvent(TestEvent);\n```\n\n## Additional Examples\nFor additional examples, take a look at the [Example class](https://github.com/Ellpeck/Coroutine/blob/main/Example/Example.cs).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fellpeck%2Fcoroutine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fellpeck%2Fcoroutine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fellpeck%2Fcoroutine/lists"}