Skip to content

Instantly share code, notes, and snippets.

@zaafar
Created March 16, 2021 23:25
Show Gist options
  • Save zaafar/0a4fa1a711e9e7bfb92fc7c4d83ec912 to your computer and use it in GitHub Desktop.
Save zaafar/0a4fa1a711e9e7bfb92fc7c4d83ec912 to your computer and use it in GitHub Desktop.
internal static class Example {
private static IEnumerator<Wait> iwillnotrun()
{
while (true)
{
Console.WriteLine($"Inside iwillnotrun while loop");
Console.WriteLine($"I should run forever.");
yield return new Wait(1);
Console.WriteLine($"iwillnotrun");
Console.WriteLine($"iwillnotrun");
Console.WriteLine($"iwillnotrun");
Console.WriteLine($"iwillnotrun");
}
}
private static IEnumerator<Wait> iwillalwaysrunforever()
{
while (true)
{
Console.WriteLine($"iwillalwaysrunforever");
yield return new Wait(1);
}
}
private static IEnumerator<Wait> iwillrunonce()
{
Console.WriteLine($"iwillalwaysrunforever");
yield return new Wait(1);
CoroutineHandler.Start(iwillnotrun());
}
public static void Main() {
CoroutineHandler.Start(iwillalwaysrunforever());
CoroutineHandler.Start(iwillrunonce());
var lastTime = DateTime.Now;
while (true) {
var currTime = DateTime.Now;
CoroutineHandler.Tick((currTime - lastTime).TotalSeconds);
lastTime = currTime;
Thread.Sleep(1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment