Skip to content

Instantly share code, notes, and snippets.

@sdether
Created January 12, 2012 07:14
Show Gist options
  • Select an option

  • Save sdether/1599207 to your computer and use it in GitHub Desktop.

Select an option

Save sdether/1599207 to your computer and use it in GitHub Desktop.
class Consumer {
public static IEnumerator Coroutine(int[,] destination, Coordinator<int[]> coordinator) {
Console.WriteLine("consumer started");
int i = 0, j = 0;
while(true) {
Console.WriteLine("yielding to producer");
yield return null;
if(coordinator.State == null) {
continue;
}
if(coordinator.State.Length == 0) {
Console.WriteLine("consumer finished, end of input");
yield break;
}
foreach(var item in coordinator.State) {
destination[i, j] = item;
Console.WriteLine("wrote {0} to [{1},{2}]", item, i, j);
j++;
if(j != destination.GetLength(1)) {
continue;
}
j = 0;
i++;
if(i != destination.GetLength(0)) {
continue;
}
Console.WriteLine("consumer finished, output full");
yield break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment