Skip to content

Commit 6a82f2d

Browse files
author
Oren (electricessence)
committed
Cleanup.
1 parent 96f2009 commit 6a82f2d

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

ActionRunner.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,8 @@ public Exception LastFault
7171
public bool Cancel(bool onlyIfNotRunning)
7272
{
7373
var t = _task;
74-
if (t?.Cancel(onlyIfNotRunning) ?? false)
75-
{
76-
Interlocked.CompareExchange(ref _task, null, t);
77-
return true;
78-
}
79-
return false;
74+
return t?.Cancel(onlyIfNotRunning) ?? false
75+
&& t == Interlocked.CompareExchange(ref _task, null, t);
8076
}
8177

8278
public bool Cancel()
@@ -150,10 +146,10 @@ public CancellableTask Defer(TimeSpan delay, bool clearSchedule = true)
150146
}
151147

152148
CancellableTask task = null;
153-
if((task = _task) == null)
149+
if ((task = _task) == null)
154150
{
155151
task = Prepare();
156-
if(task==Interlocked.CompareExchange(ref _task, task, null))
152+
if (task == Interlocked.CompareExchange(ref _task, task, null))
157153
{
158154
task.Start(delay);
159155
}

0 commit comments

Comments
 (0)