-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathExtensions.cs
39 lines (35 loc) · 976 Bytes
/
Extensions.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AsyncAndPromises
{
/// <summary>
/// Just add custom methods to Existing classes.
/// It makes syntax like JavaScript
/// </summary>
public static class Extensions
{
public static Task Then(this Task task, Task nextTask)
{
task.ContinueWith(t =>
{
if (!nextTask.IsCanceled)
nextTask.Start();
});
return nextTask;
}
public static Task Then(this Task task, Action nextAction)
{
var nextTask = new Task(nextAction);
return task.Then(nextTask);
}
public static Task Then(this Action action, Action nextAction)
{
var rootTask = new Task(action);
rootTask.Start();
return rootTask.Then(nextAction);
}
}
}