Fiber
Fibers Lighweight Cooperative Multitasking
TaskWorker.cs
1 // Copyright 2018 (C) paul@marrington.net http://www.askowl.net/unity-packages
2 
3 using System;
4 
5 namespace Askowl {
6  using System.Threading.Tasks;
7 
8  // ReSharper disable once ClassNeverInstantiated.Global
9  public partial class Fiber {
10  /// <a href="http://bit.ly/2RcQM7a">Convert Task activities to Coroutines to behave well with the rest of Unity</a>
11  public Fiber WaitFor(Task task) =>
12  AddAction(
13  _ => {
14  var emitter = Emitter.SingleFireInstance;
15  void action(Task __) => emitter.Fire();
16  task.ContinueWith(action);
17  EmitterWorker.Instance.Load(this, emitter);
18  }, "WaitFor(Task)");
19 
20  /// <a href="http://bit.ly/2RcQM7a">Convert Task activities to Coroutines to behave well with the rest of Unity - value passed by function return</a>
21  public Fiber WaitFor(Func<Fiber, Task> getTask) =>
22  AddAction(
23  _ => {
24  var emitter = Emitter.SingleFireInstance;
25  void action(Task __) => emitter.Fire();
26  getTask(this).ContinueWith(action);
27  EmitterWorker.Instance.Load(this, emitter);
28  }, "WaitFor(Task)");
29  }
30 }
Definition: Emitter.cs:6
Fiber WaitFor(IClosure closure)
Helper that is the same as fiber.WaitFor(closure.OnComplete)