-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (TaskCompletionSourceRCA.cs): introduce this new utility class w…
…hich ensures that the TaskCreationOptions.RunContinuationsAsynchronously is turned on for all constructors - also employ it in all operations
- Loading branch information
1 parent
c94dd20
commit a1dc16c
Showing
7 changed files
with
102 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
Laerdal.McuMgr/Shared/Common/Helpers/TaskCompletionSourceRCA.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace Laerdal.McuMgr.Common.Helpers | ||
{ | ||
/// <summary>Like <see cref="TaskCompletionSource"/> but with <see cref="TaskCreationOptions"/>.<see cref="TaskCreationOptions.RunContinuationsAsynchronously"/> turned on by default in all constructors.</summary> | ||
/// <remarks> | ||
/// Inspired by <see href="https://devblogs.microsoft.com/premier-developer/the-danger-of-taskcompletionsourcet-class/">Microsoft's recommendation on TCS</see> which strongly | ||
/// advises using <see cref="TaskCreationOptions"/>.<see cref="TaskCreationOptions.RunContinuationsAsynchronously"/> with <see cref="TaskCompletionSource"/> to avoid exotic deadlocks in certain corner-cases. | ||
/// </remarks> | ||
internal sealed class TaskCompletionSourceRCA : TaskCompletionSource | ||
{ | ||
/// <summary>Like <see cref="TaskCompletionSource"/> but with the <see cref="TaskCreationOptions"/>.<see cref="TaskCreationOptions.RunContinuationsAsynchronously"/> turned on by default in all constructors.</summary> | ||
/// <remarks> | ||
/// Inspired by <see href="https://devblogs.microsoft.com/premier-developer/the-danger-of-taskcompletionsourcet-class/">Microsoft's recommendation on TCS</see> which strongly | ||
/// advises using <see cref="TaskCreationOptions"/>.<see cref="TaskCreationOptions.RunContinuationsAsynchronously"/> with <see cref="TaskCompletionSource"/> to avoid exotic deadlocks in certain corner-cases. | ||
/// </remarks> | ||
public TaskCompletionSourceRCA() : base(TaskCreationOptions.RunContinuationsAsynchronously) | ||
{ | ||
} | ||
|
||
/// <summary>Like <see cref="TaskCompletionSource"/> but with <see cref="TaskCreationOptions"/>.<see cref="TaskCreationOptions.RunContinuationsAsynchronously"/> turned on by default in all constructors.</summary> | ||
/// <remarks> | ||
/// Inspired by <see href="https://devblogs.microsoft.com/premier-developer/the-danger-of-taskcompletionsourcet-class/">Microsoft's recommendation on TCS</see> which strongly | ||
/// advises using <see cref="TaskCreationOptions"/>.<see cref="TaskCreationOptions.RunContinuationsAsynchronously"/> with <see cref="TaskCompletionSource"/> to avoid exotic deadlocks in certain corner-cases. | ||
/// </remarks> | ||
public TaskCompletionSourceRCA(object state) : base(state, TaskCreationOptions.RunContinuationsAsynchronously) | ||
{ | ||
} | ||
|
||
/// <summary>Like <see cref="TaskCompletionSource"/> but with <see cref="TaskCreationOptions"/>.<see cref="TaskCreationOptions.RunContinuationsAsynchronously"/> turned on by default in all constructors.</summary> | ||
/// <remarks> | ||
/// Inspired by <see href="https://devblogs.microsoft.com/premier-developer/the-danger-of-taskcompletionsourcet-class/">Microsoft's recommendation on TCS</see> which strongly | ||
/// advises using <see cref="TaskCreationOptions"/>.<see cref="TaskCreationOptions.RunContinuationsAsynchronously"/> with <see cref="TaskCompletionSource"/> to avoid exotic deadlocks in certain corner-cases. | ||
/// </remarks> | ||
public TaskCompletionSourceRCA(object state, TaskCreationOptions creationOptions) : base(state, creationOptions | TaskCreationOptions.RunContinuationsAsynchronously) | ||
{ | ||
} | ||
|
||
/// <summary>Like <see cref="TaskCompletionSource"/> but with <see cref="TaskCreationOptions"/>.<see cref="TaskCreationOptions.RunContinuationsAsynchronously"/> turned on by default in all constructors.</summary> | ||
/// <remarks> | ||
/// Inspired by <see href="https://devblogs.microsoft.com/premier-developer/the-danger-of-taskcompletionsourcet-class/">Microsoft's recommendation on TCS</see> which strongly | ||
/// advises using <see cref="TaskCreationOptions"/>.<see cref="TaskCreationOptions.RunContinuationsAsynchronously"/> with <see cref="TaskCompletionSource"/> to avoid exotic deadlocks in certain corner-cases. | ||
/// </remarks> | ||
public TaskCompletionSourceRCA(TaskCreationOptions creationOptions) : base(creationOptions | TaskCreationOptions.RunContinuationsAsynchronously) | ||
{ | ||
} | ||
} | ||
|
||
/// <summary>Like <see cref="TaskCompletionSource{T}"/> but with <see cref="TaskCreationOptions"/>.<see cref="TaskCreationOptions.RunContinuationsAsynchronously"/> turned on by default in all constructors.</summary> | ||
/// <remarks> | ||
/// Inspired by <see href="https://devblogs.microsoft.com/premier-developer/the-danger-of-taskcompletionsourcet-class/">Microsoft's recommendation on TCS</see> which strongly | ||
/// advises using <see cref="TaskCreationOptions"/>.<see cref="TaskCreationOptions.RunContinuationsAsynchronously"/> with <see cref="TaskCompletionSource{T}"/> to avoid exotic deadlocks in certain corner-cases. | ||
/// </remarks> | ||
internal sealed class TaskCompletionSourceRCA<T> : TaskCompletionSource<T> | ||
{ | ||
/// <summary>Like <see cref="TaskCompletionSource{T}"/> but with the <see cref="TaskCreationOptions"/>.<see cref="TaskCreationOptions.RunContinuationsAsynchronously"/> turned on by default in all constructors.</summary> | ||
/// <remarks> | ||
/// Inspired by <see href="https://devblogs.microsoft.com/premier-developer/the-danger-of-taskcompletionsourcet-class/">Microsoft's recommendation on TCS</see> which strongly | ||
/// advises using <see cref="TaskCreationOptions"/>.<see cref="TaskCreationOptions.RunContinuationsAsynchronously"/> with <see cref="TaskCompletionSource{T}"/> to avoid exotic deadlocks in certain corner-cases. | ||
/// </remarks> | ||
public TaskCompletionSourceRCA() : base(TaskCreationOptions.RunContinuationsAsynchronously) | ||
{ | ||
} | ||
|
||
/// <summary>Like <see cref="TaskCompletionSource{T}"/> but with <see cref="TaskCreationOptions"/>.<see cref="TaskCreationOptions.RunContinuationsAsynchronously"/> turned on by default in all constructors.</summary> | ||
/// <remarks> | ||
/// Inspired by <see href="https://devblogs.microsoft.com/premier-developer/the-danger-of-taskcompletionsourcet-class/">Microsoft's recommendation on TCS</see> which strongly | ||
/// advises using <see cref="TaskCreationOptions"/>.<see cref="TaskCreationOptions.RunContinuationsAsynchronously"/> with <see cref="TaskCompletionSource{T}"/> to avoid exotic deadlocks in certain corner-cases. | ||
/// </remarks> | ||
public TaskCompletionSourceRCA(object state) : base(state, TaskCreationOptions.RunContinuationsAsynchronously) | ||
{ | ||
} | ||
|
||
/// <summary>Like <see cref="TaskCompletionSource{T}"/> but with <see cref="TaskCreationOptions"/>.<see cref="TaskCreationOptions.RunContinuationsAsynchronously"/> turned on by default in all constructors.</summary> | ||
/// <remarks> | ||
/// Inspired by <see href="https://devblogs.microsoft.com/premier-developer/the-danger-of-taskcompletionsourcet-class/">Microsoft's recommendation on TCS</see> which strongly | ||
/// advises using <see cref="TaskCreationOptions"/>.<see cref="TaskCreationOptions.RunContinuationsAsynchronously"/> with <see cref="TaskCompletionSource{T}"/> to avoid exotic deadlocks in certain corner-cases. | ||
/// </remarks> | ||
public TaskCompletionSourceRCA(object state, TaskCreationOptions creationOptions) : base(state, creationOptions | TaskCreationOptions.RunContinuationsAsynchronously) | ||
{ | ||
} | ||
|
||
/// <summary>Like <see cref="TaskCompletionSource{T}"/> but with <see cref="TaskCreationOptions"/>.<see cref="TaskCreationOptions.RunContinuationsAsynchronously"/> turned on by default in all constructors.</summary> | ||
/// <remarks> | ||
/// Inspired by <see href="https://devblogs.microsoft.com/premier-developer/the-danger-of-taskcompletionsourcet-class/">Microsoft's recommendation on TCS</see> which strongly | ||
/// advises using <see cref="TaskCreationOptions"/>.<see cref="TaskCreationOptions.RunContinuationsAsynchronously"/> with <see cref="TaskCompletionSource{T}"/> to avoid exotic deadlocks in certain corner-cases. | ||
/// </remarks> | ||
public TaskCompletionSourceRCA(TaskCreationOptions creationOptions) : base(creationOptions | TaskCreationOptions.RunContinuationsAsynchronously) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters