forked from cschladetsch/CsharpFlow
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFactory.cs
More file actions
158 lines (134 loc) · 3.69 KB
/
Factory.cs
File metadata and controls
158 lines (134 loc) · 3.69 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// (C) 2012 Christian Schladetsch. See http://www.schladetsch.net/flow/license.txt for Licensing information.
using System;
using System.Collections.Generic;
namespace Flow
{
/// <summary>
/// Makes instances for the Flow library
/// </summary>
public class Factory : IFactory
{
/// <inheritdoc />
public IKernel Kernel { get; internal set; }
/// <inheritdoc />
public ITimer NewTimer (TimeSpan interval)
{
var timer = new Timer(Kernel, interval);
return Prepare(timer);
}
/// <inheritdoc />
public IPeriodic NewPeriodicTimer (TimeSpan interval)
{
var timer = new Periodic(Kernel, interval);
return Prepare(timer);
}
/// <inheritdoc />
public IBarrier NewBarrier()
{
return Prepare(new Barrier());
}
/// <inheritdoc />
public ITrigger NewTrigger()
{
return Prepare(new Trigger());
}
/// <inheritdoc />
public ITimedTrigger NewTimedTrigger(TimeSpan span)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public IFuture<T> NewFuture<T>()
{
return Prepare(new Future<T>());
}
/// <inheritdoc />
public ITimedFuture<T> NewTimedFuture<T> (TimeSpan interval)
{
return Prepare(new TimedFuture<T>(Kernel, interval));
}
/// <inheritdoc />
public ISubroutine<TR> NewSubroutine<TR>(Func<IGenerator, TR> fun)
{
var sub = new Subroutine<TR>();
sub.Sub = (tr) => fun(sub);
return Prepare(sub);
}
/// <inheritdoc />
public ISubroutine<TR> NewSubroutine<TR, T0> (Func<IGenerator, T0, TR> fun, T0 t0)
{
var sub = new Subroutine<TR>();
sub.Sub = (tr) => fun(sub, t0);
return Prepare(sub);
}
/// <inheritdoc />
public ISubroutine<TR> NewSubroutine<TR, T0, T1> (Func<IGenerator, T0, T1, TR> fun, T0 t0, T1 t1)
{
var sub = new Subroutine<TR>();
sub.Sub = (tr) => fun(sub, t0, t1);
return Prepare(sub);
}
/// <inheritdoc />
public ISubroutine<TR> NewSubroutine<TR, T0, T1, T2> (Func<IGenerator, T0, T1, T2, TR> fun, T0 t0, T1 t1, T2 t2)
{
var sub = new Subroutine<TR>();
sub.Sub = (tr) => fun(sub, t0, t1, t2);
return Prepare(sub);
}
/// <inheritdoc />
public ICoroutine<TR> NewCoroutine<TR>(Func<IGenerator, IEnumerator<TR>> fun)
{
var coro = new Coroutine<TR>();
coro.Start = () => fun(coro);
return Prepare(coro);
}
/// <inheritdoc />
public ICoroutine<TR> NewCoroutine<TR, T0>(Func<IGenerator, T0, IEnumerator<TR>> fun, T0 t0)
{
var coro = new Coroutine<TR>();
coro.Start = () => fun(coro, t0);
return Prepare(coro);
}
/// <inheritdoc />
public ICoroutine<TR> NewCoroutine<TR, T0, T1>(Func<IGenerator, T0, T1, IEnumerator<TR>> fun, T0 t0, T1 t1)
{
var coro = new Coroutine<TR>();
coro.Start = () => fun(coro, t0, t1);
return Prepare(coro);
}
/// <inheritdoc />
public ICoroutine<TR> NewCoroutine<TR, T0, T1, T2>(Func<IGenerator, T0, T1, T2, IEnumerator<TR>> fun, T0 t0, T1 t1, T2 t2)
{
var coro = new Coroutine<TR>();
coro.Start = () => fun(coro, t0, t1, t2);
return Prepare(coro);
}
/// <inheritdoc />
public ICoroutine<TR> NewCoroutine<TR, T0, T1, T2, T3>(Func<IGenerator, T0, T1, T2, T3, IEnumerator<TR>> fun, T0 t0, T1 t1, T2 t2, T3 t3)
{
var coro = new Coroutine<TR>();
coro.Start = () => fun(coro, t0, t1, t2, t3);
return Prepare(coro);
}
/// <inheritdoc />
public IChannel<TR> NewChannel<TR>(ITypedGenerator<TR> gen)
{
return Prepare(new Channel<TR>(Kernel, gen));
}
/// <inheritdoc />
public IChannel<TR> NewChannel<TR>()
{
return Prepare(new Channel<TR>(Kernel));
}
/// <inheritdoc />
public T Prepare<T>(T obj) where T : ITransient
{
obj.Kernel = Kernel;
var gen = obj as IGenerator;
if (gen != null)
gen.Resume();
Kernel.Root.Add(obj);
return obj;
}
}
}