-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove source-only package #11006
Remove source-only package #11006
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
||
// https://github.com/dotnet/runtime/blob/11c86d8acba2f248b3afb5e8594f5f41ceebf098/src/libraries/Common/src/Extensions/NonCapturingTimer/NonCapturingTimer.cs | ||
|
||
using System; | ||
using System.Threading; | ||
|
||
namespace Microsoft.Extensions.Internal; | ||
|
||
// A convenience API for interacting with System.Threading.Timer in a way | ||
// that doesn't capture the ExecutionContext. We should be using this (or equivalent) | ||
// everywhere we use timers to avoid rooting any values stored in asynclocals. | ||
internal static class NonCapturingTimer | ||
{ | ||
public static Timer Create(TimerCallback callback, object state, TimeSpan dueTime, TimeSpan period) | ||
{ | ||
if (callback is null) | ||
{ | ||
throw new ArgumentNullException(nameof(callback)); | ||
} | ||
|
||
// Don't capture the current ExecutionContext and its AsyncLocals onto the timer | ||
var restoreFlow = false; | ||
try | ||
{ | ||
if (!ExecutionContext.IsFlowSuppressed()) | ||
{ | ||
ExecutionContext.SuppressFlow(); | ||
restoreFlow = true; | ||
} | ||
|
||
return new Timer(callback, state, dueTime, period); | ||
} | ||
finally | ||
{ | ||
// Restore the current ExecutionContext | ||
if (restoreFlow) | ||
{ | ||
ExecutionContext.RestoreFlow(); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought our CI should have caught these types of things :( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it was disabled before
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, derp, yep. I missed that entirely. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we have nullable analysis so we don't need to do null checks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but I'm not sure it's a good idea to modify the copied source very much in case we want to update it from the upstream later.