mirror of
https://github.com/FabInfra/capnproto-dotnetcore_Runtime.git
synced 2025-03-12 23:01:44 +01:00
added missing documentation
This commit is contained in:
parent
8f74ad79c0
commit
16f95e8f8f
@ -7,6 +7,11 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Capnp.Util
|
||||
{
|
||||
/// <summary>
|
||||
/// A task-like object which enforces that all await operations from the same thread leave in the exact order they were issued.
|
||||
/// Note that an ordinary .NET Task does not fulfill this requirement if completed by a thread which is different from the
|
||||
/// awaiting thread.
|
||||
/// </summary>
|
||||
public class StrictlyOrderedAwaitTask: INotifyCompletion
|
||||
{
|
||||
class Cover { }
|
||||
@ -18,12 +23,20 @@ namespace Capnp.Util
|
||||
readonly Task _awaitedTask;
|
||||
object? _state;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an instance
|
||||
/// </summary>
|
||||
/// <param name="awaitedTask">Task on which the order shall be enforced</param>
|
||||
public StrictlyOrderedAwaitTask(Task awaitedTask)
|
||||
{
|
||||
_awaitedTask = awaitedTask;
|
||||
_state = s_cover;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// await pattern implementation
|
||||
/// </summary>
|
||||
/// <returns>An object suitable for the await pattern</returns>
|
||||
public StrictlyOrderedAwaitTask GetAwaiter()
|
||||
{
|
||||
return this;
|
||||
@ -55,6 +68,9 @@ namespace Capnp.Util
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Part of await pattern implementation. Do not use directly.
|
||||
/// </summary>
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
bool first = false;
|
||||
@ -92,36 +108,82 @@ namespace Capnp.Util
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the underlying task did complete and it is safe to skip continuation registration.
|
||||
/// </summary>
|
||||
public bool IsCompleted => _awaitedTask.IsCompleted && _state == s_seal;
|
||||
|
||||
/// <summary>
|
||||
/// Part of await pattern implementation. Do not use directly.
|
||||
/// </summary>
|
||||
public void GetResult() => _awaitedTask.GetAwaiter().GetResult();
|
||||
|
||||
/// <summary>
|
||||
/// Task on which the order shall be enforced.
|
||||
/// </summary>
|
||||
public Task WrappedTask => _awaitedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A task-like object which enforces that all await operations from the same thread leave in the exact order they were issued.
|
||||
/// Note that an ordinary .NET Task does not fulfill this requirement if completed by a thread which is different from the
|
||||
/// awaiting thread.
|
||||
/// </summary>
|
||||
public class StrictlyOrderedAwaitTask<T> : StrictlyOrderedAwaitTask
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an instance
|
||||
/// </summary>
|
||||
/// <param name="awaitedTask">Task on which the order shall be enforced</param>
|
||||
public StrictlyOrderedAwaitTask(Task<T> awaitedTask): base(awaitedTask)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Task on which the order shall be enforced.
|
||||
/// </summary>
|
||||
public new Task<T> WrappedTask => (Task<T>)base.WrappedTask;
|
||||
|
||||
/// <summary>
|
||||
/// await pattern implementation
|
||||
/// </summary>
|
||||
/// <returns>An object suitable for the await pattern</returns>
|
||||
public new StrictlyOrderedAwaitTask<T> GetAwaiter() => this;
|
||||
|
||||
/// <summary>
|
||||
/// Part of await pattern implementation. Do not use directly.
|
||||
/// </summary>
|
||||
public new T GetResult() => WrappedTask.GetAwaiter().GetResult();
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the wrapped Task's result.
|
||||
/// </summary>
|
||||
public T Result => WrappedTask.Result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods to simplify the use of <see cref="StrictlyOrderedAwaitTask"/>
|
||||
/// </summary>
|
||||
public static class StrictlyOrderedTaskExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts the task to a task-like object which enforces that all await operations from the same thread leave in the exact order they were issued.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the result produced by the Task</typeparam>
|
||||
/// <param name="task">Task to wrap</param>
|
||||
/// <returns>awaitable object</returns>
|
||||
public static StrictlyOrderedAwaitTask<T> EnforceAwaitOrder<T>(this Task<T> task)
|
||||
{
|
||||
return new StrictlyOrderedAwaitTask<T>(task);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the task to a task-like object which enforces that all await operations from the same thread leave in the exact order they were issued.
|
||||
/// </summary>
|
||||
/// <param name="task">Task to wrap</param>
|
||||
/// <returns>awaitable object</returns>
|
||||
public static StrictlyOrderedAwaitTask EnforceAwaitOrder(this Task task)
|
||||
{
|
||||
return new StrictlyOrderedAwaitTask(task);
|
||||
|
Loading…
x
Reference in New Issue
Block a user