Empeld
Empeld plugin documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events
pluginbase.Objects.Tasks.YieldingTask Class Reference
Inheritance diagram for pluginbase.Objects.Tasks.YieldingTask:
pluginbase.Objects.Tasks.ITask

Public Member Functions

 YieldingTask (Func< IEnumerable< ITaskYieldAction >> method, TimeSpan delay)
 
 YieldingTask (Func< IEnumerable< ITaskYieldAction >> method)
 
TaskResult InvokeTask (long maxMilliseconds)
 

Static Public Member Functions

static ITaskYieldAction Task (ITask task)
 Yield a new task to run here More...
 
static ITaskYieldAction Task (Func< IEnumerable< ITaskYieldAction >> task)
 Yield a new task to run here More...
 
static ITaskYieldAction Wait (Func< bool > predicate, TimeSpan checkTime)
 Wait until the predicate is true, checking every amount of time More...
 
static ITaskYieldAction Wait (TimeSpan time)
 Wait the specified time More...
 
static ITaskYieldAction Wait (Func< bool > predicate)
 Wait for the predicate to be true More...
 
static ITaskYieldAction Wait (double seconds)
 Wait the specified number of seconds More...
 

Properties

TimeSpan Frequency [get]
 
static ITaskYieldAction Next [get]
 Yields to the next scheduled task. Will start again in the next tick More...
 
static ITaskYieldAction Reset [get]
 Restarts the task over from the beginning More...
 
- Properties inherited from pluginbase.Objects.Tasks.ITask
TimeSpan Frequency [get]
 

Constructor & Destructor Documentation

pluginbase.Objects.Tasks.YieldingTask.YieldingTask ( Func< IEnumerable< ITaskYieldAction >>  method,
TimeSpan  delay 
)
15  {
16  _method = method;
17  _iter = method().GetEnumerator();
18  this.Frequency = delay;
19  }
TimeSpan Frequency
Definition: YieldingTask.cs:89
pluginbase.Objects.Tasks.YieldingTask.YieldingTask ( Func< IEnumerable< ITaskYieldAction >>  method)
22  :this(method, TimeSpan.Zero)
23  { }

Member Function Documentation

TaskResult pluginbase.Objects.Tasks.YieldingTask.InvokeTask ( long  maxMilliseconds)

Implements pluginbase.Objects.Tasks.ITask.

27  {
28  if (_blockingPredicate != null)
29  {
30  if (_blockingPredicate())
31  {
32  _blockingPredicate = null;
33  }
34  else
35  {
36  return TaskResult.Continue; //need to wait
37  }
38  }
39 
40  if (_chainedTask != null)
41  {
42  var result = _chainedTask.InvokeTask(maxMilliseconds);
43  if (result == TaskResult.Continue)
44  {
45  this.Frequency = _chainedTask.Frequency;
46  return TaskResult.Continue;
47  }
48  _chainedTask = null;
49  }
50 
51  if (_iter.MoveNext())
52  {
53  if (_iter.Current is YieldWait)
54  {
55  var wait = _iter.Current as YieldWait;
56  this.Frequency = wait.Wait;
57  this._blockingPredicate = wait.Predicate;
58  }
59  else if (_iter.Current is YieldReset)
60  {
61  _iter = _method().GetEnumerator();
62  this.Frequency = TimeSpan.Zero;
63  }
64  else if(_iter.Current is YieldNext)
65  {
66  //Nothing
67  this.Frequency = TimeSpan.Zero;
68  }
69  else if(_iter.Current is YieldTask)
70  {
71  var task = _iter.Current as YieldTask;
72  _chainedTask = task.Task;
73  this.Frequency = _chainedTask.Frequency;
74  }
75  else
76  {
77  throw new InvalidOperationException("Unknown TaskYieldAction type");
78  }
79 
80 
81  return TaskResult.Continue;
82  }
83  else
84  {
85  return TaskResult.Remove;
86  }
87  }
TimeSpan Frequency
Definition: YieldingTask.cs:89
TaskResult
The result of a scheduled task
Definition: TaskResult.cs:8
TaskResult InvokeTask(long maxMilliseconds)
TimeSpan Frequency
Definition: ITask.cs:7
static ITaskYieldAction pluginbase.Objects.Tasks.YieldingTask.Task ( ITask  task)
static

Yield a new task to run here

Parameters
taskTask.
121  {
122  return new YieldTask(task);
123  }
static ITaskYieldAction pluginbase.Objects.Tasks.YieldingTask.Task ( Func< IEnumerable< ITaskYieldAction >>  task)
static

Yield a new task to run here

Parameters
taskTask.
130  {
131  return new YieldTask(new YieldingTask(task));
132  }
YieldingTask(Func< IEnumerable< ITaskYieldAction >> method, TimeSpan delay)
Definition: YieldingTask.cs:14
static ITaskYieldAction pluginbase.Objects.Tasks.YieldingTask.Wait ( Func< bool >  predicate,
TimeSpan  checkTime 
)
static

Wait until the predicate is true, checking every amount of time

Parameters
predicatePredicate.
checkTimeCheck time.
140  {
141  return new YieldWait(predicate, checkTime);
142  }
static ITaskYieldAction pluginbase.Objects.Tasks.YieldingTask.Wait ( TimeSpan  time)
static

Wait the specified time

Parameters
timeTime.
149  {
150  return new YieldWait(time);
151  }
static ITaskYieldAction pluginbase.Objects.Tasks.YieldingTask.Wait ( Func< bool >  predicate)
static

Wait for the predicate to be true

Parameters
predicatePredicate.
158  {
159  return new YieldWait(predicate, TimeSpan.FromSeconds(0.5));
160  }
static ITaskYieldAction pluginbase.Objects.Tasks.YieldingTask.Wait ( double  seconds)
static

Wait the specified number of seconds

Parameters
secondsSeconds.
167  {
168  return new YieldWait(TimeSpan.FromSeconds(seconds));
169  }

Property Documentation

TimeSpan pluginbase.Objects.Tasks.YieldingTask.Frequency
get
ITaskYieldAction pluginbase.Objects.Tasks.YieldingTask.Next
staticget

Yields to the next scheduled task. Will start again in the next tick

ITaskYieldAction pluginbase.Objects.Tasks.YieldingTask.Reset
staticget

Restarts the task over from the beginning

The reset.


The documentation for this class was generated from the following file: