Skip to content

Commit

Permalink
Use new CancellationToken API on netcoreapp3.0 (dotnet/extensions#1424)
Browse files Browse the repository at this point in the history
Commit migrated from dotnet/extensions@f79dfbc
  • Loading branch information
davidfowl authored Apr 15, 2019
1 parent 83d0dac commit 952a626
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ public CancellationChangeToken(CancellationToken cancellationToken)
/// <inheritdoc />
public IDisposable RegisterChangeCallback(Action<object> callback, object state)
{
#if NETCOREAPP3_0
try
{
return Token.UnsafeRegister(callback, state);
}
catch (ObjectDisposedException)
{
// Reset the flag so that we can indicate to future callers that this wouldn't work.
ActiveChangeCallbacks = false;
}
#else
// Don't capture the current ExecutionContext and its AsyncLocals onto the token registration causing them to live forever
var restoreFlow = false;
if (!ExecutionContext.IsFlowSuppressed())
Expand All @@ -56,7 +67,7 @@ public IDisposable RegisterChangeCallback(Action<object> callback, object state)
ExecutionContext.RestoreFlow();
}
}

#endif
return NullDisposable.Instance;
}

Expand Down

0 comments on commit 952a626

Please sign in to comment.