Skip to content

Commit 0cb86fc

Browse files
author
Oren (electricessence)
committed
Reformat and contract improvments.
1 parent ea0729d commit 0cb86fc

4 files changed

Lines changed: 16 additions & 17 deletions

File tree

ActionRunner.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Threading;
33
using System.Threading.Tasks;
4-
using Open.Threading;
54

65
namespace Open.Threading.Tasks
76
{
@@ -71,7 +70,7 @@ public Exception LastFault
7170
public bool Cancel(bool onlyIfNotRunning)
7271
{
7372
var t = _task;
74-
return t!=null
73+
return t != null
7574
&& t == Interlocked.CompareExchange(ref _task, null, t)
7675
&& t.Cancel(onlyIfNotRunning);
7776
}

CancellableTask.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@ public static CancellableTask StartNew(Action<CancellationToken> action, TimeSpa
128128
{
129129
var ts = new CancellationTokenSource();
130130
var token = ts.Token;
131-
var task = new CancellableTask(()=>action(token), token)
131+
var task = new CancellableTask(() => action(token), token)
132132
{
133133
TokenSource = ts
134134
};
135135
task.Start(delay ?? TimeSpan.Zero, scheduler);
136136
return task;
137137
}
138138
}
139-
139+
140140
}

TaskExtensions.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Threading.Tasks;
33

44
namespace Open.Threading.Tasks
@@ -21,10 +21,10 @@ public static bool IsActive(this Task target)
2121
case TaskStatus.WaitingForChildrenToComplete:
2222
case TaskStatus.WaitingToRun:
2323
return true;
24-
//case TaskStatus.Canceled:
25-
//case TaskStatus.Faulted:
26-
//case TaskStatus.RanToCompletion:
27-
// return false;
24+
//case TaskStatus.Canceled:
25+
//case TaskStatus.Faulted:
26+
//case TaskStatus.RanToCompletion:
27+
// return false;
2828
}
2929

3030
return false;
@@ -37,9 +37,9 @@ public static bool IsActive(this Task target)
3737
/// <returns>True if start attempt was successful.</returns>
3838
public static bool EnsureStarted(this Task target, TaskScheduler scheduler = null)
3939
{
40-
if(target==null) throw new NullReferenceException();
40+
if (target == null) throw new NullReferenceException();
4141

42-
if(target.Status==TaskStatus.Created)
42+
if (target.Status == TaskStatus.Created)
4343
{
4444
try
4545
{
@@ -50,7 +50,7 @@ public static bool EnsureStarted(this Task target, TaskScheduler scheduler = nul
5050

5151
return true;
5252
}
53-
catch(InvalidOperationException)
53+
catch (InvalidOperationException)
5454
{
5555
// Even though we've checked the status, it's possible it could have been started. We can't guarantee proper handling without a trap here.
5656
if (target.Status == TaskStatus.Created)
@@ -100,7 +100,7 @@ public static Task<T> OnFullfilled<T>(this Task<T> target, Action<T> action)
100100
/// <typeparam name="TTask">The return type is the same as the target.</typeparam>
101101
/// <param name="action">The action to perform if fullfulled.</param>
102102
/// <returns>The target object. Allows for method chaining.</returns>
103-
public static TTask OnFullfilled<TTask,T>(this TTask target, Func<T> action)
103+
public static TTask OnFullfilled<TTask, T>(this TTask target, Func<T> action)
104104
where TTask : Task
105105
{
106106
target.ContinueWith(task =>
@@ -164,4 +164,4 @@ public static TTask OnCancelled<TTask, T>(this TTask target, Func<T> action)
164164
}
165165

166166
}
167-
}
167+
}

TimeoutHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using System;
1+
using System;
22
using System.Threading;
33
using System.Threading.Tasks;
44

55
namespace Open.Threading.Tasks
66
{
7-
public class TimeoutHandler : IDisposable
7+
public class TimeoutHandler : IDisposable
88
{
99

1010
CancellationTokenSource TokenSource;
@@ -33,4 +33,4 @@ public void Dispose()
3333
TokenSource.Cancel();
3434
}
3535
}
36-
}
36+
}

0 commit comments

Comments
 (0)