Skip to content

Commit 5c3e2ac

Browse files
Cleanup and simplification.
1 parent 871957e commit 5c3e2ac

File tree

6 files changed

+13
-30
lines changed

6 files changed

+13
-30
lines changed

ActionRunner.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ public ActionRunner(Action action, TaskScheduler? scheduler = default)
1515
}
1616

1717
public static ActionRunner Create(Action action, TaskScheduler? scheduler = default)
18-
=> new ActionRunner(action, scheduler);
18+
=> new(action, scheduler);
1919

2020
public static ActionRunner Create<T>(Func<T> action, TaskScheduler? scheduler = default)
21-
=> new ActionRunner(() => { action(); }, scheduler);
21+
=> new(() => { action(); }, scheduler);
2222

2323
Action? _action;
2424
// ReSharper disable once NotAccessedField.Global

CancellableTask.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ namespace Open.Threading.Tasks
99
/// </summary>
1010
public class CancellableTask : Task, ICancellable
1111
{
12-
#pragma warning disable CA2213 // Is disposed in Cancel method.
1312
CancellationTokenSource? TokenSource;
14-
#pragma warning restore CA2213
1513

1614
public bool Cancel(bool onlyIfNotRunning)
1715
{

ICancellable.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace Open.Threading.Tasks
55
{
6-
[SuppressMessage("ReSharper", "UnusedMemberInSuper.Global")]
76
public interface ICancellable : IDisposable
87
{
98
/// <summary>

Open.Threading.Tasks.csproj

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@
2727
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
2828
</ItemGroup>
2929

30-
<ItemGroup>
31-
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0">
32-
<PrivateAssets>all</PrivateAssets>
33-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
34-
</PackageReference>
35-
</ItemGroup>
36-
3730
<ItemGroup>
3831
<None Remove=".editorconfig" />
3932
<None Remove=".git" />

TaskExtensions.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,15 @@ public static bool IsActive(this Task target)
1212
{
1313
if (target is null) throw new ArgumentNullException(nameof(target));
1414

15-
switch (target.Status)
15+
return target.Status switch
1616
{
17-
case TaskStatus.Created:
18-
case TaskStatus.Running:
19-
case TaskStatus.WaitingForActivation:
20-
case TaskStatus.WaitingForChildrenToComplete:
21-
case TaskStatus.WaitingToRun:
22-
return true;
23-
//case TaskStatus.Canceled:
24-
//case TaskStatus.Faulted:
25-
//case TaskStatus.RanToCompletion:
26-
// return false;
27-
}
28-
29-
return false;
17+
TaskStatus.Created or
18+
TaskStatus.Running or
19+
TaskStatus.WaitingForActivation or
20+
TaskStatus.WaitingForChildrenToComplete or
21+
TaskStatus.WaitingToRun => true,
22+
_ => false,
23+
};
3024
}
3125

3226
/// <summary>

TimeoutHandler.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,20 @@ namespace Open.Threading.Tasks
66
{
77
public sealed class TimeoutHandler : IDisposable
88
{
9-
#pragma warning disable CA2213 // Is disposed properly.
109
CancellationTokenSource? TokenSource;
11-
#pragma warning restore CA2213
10+
1211
TimeoutHandler(TimeSpan delay, Action<TimeSpan> onTimeout)
1312
{
1413
TokenSource = new CancellationTokenSource();
1514
Task.Delay(delay, TokenSource.Token).ContinueWith(t =>
1615
{
17-
Interlocked.Exchange(ref TokenSource, null)?.Dispose();
16+
Interlocked.Exchange(ref TokenSource, null!)?.Dispose();
1817
if (!t.IsCanceled) onTimeout(delay);
1918
});
2019
}
2120

2221
public static TimeoutHandler New(TimeSpan delay, Action<TimeSpan> onTimeout)
23-
=> new TimeoutHandler(delay, onTimeout);
22+
=> new(delay, onTimeout);
2423

2524
public static bool New(TimeSpan delay, out IDisposable timeout, Action<TimeSpan> onTimeout)
2625
{

0 commit comments

Comments
 (0)