forked from cschladetsch/CsharpFlow
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCoroutine.cs
More file actions
46 lines (37 loc) · 778 Bytes
/
Coroutine.cs
File metadata and controls
46 lines (37 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// (C) 2012 Christian Schladetsch. See http://www.schladetsch.net/flow/license.txt for Licensing information.
using System;
using System.Collections.Generic;
namespace Flow
{
/// <inheritdoc />
internal class Coroutine<TR> : Generator<TR>, ICoroutine<TR>
{
/// <inheritdoc />
public override void Step ()
{
if (!Running || !Active)
return;
if (_state == null)
{
if (Start == null)
CannotStart();
_state = Start();
if (_state == null)
CannotStart();
}
if (!_state.MoveNext())
{
Complete();
return;
}
Value = _state.Current;
base.Step();
}
void CannotStart ()
{
throw new Exception("Coroutine cannot start");
}
private IEnumerator<TR> _state;
internal Func<IEnumerator<TR>> Start;
}
}