예제 #1
0
        /// <summary> Enqueue asynchronous access action into work queue with given <paramref name="priority" /> (if supported) </summary>
        /// <param name="queue"> Work queue instance </param>
        /// <param name="access"> Access action instance </param>
        /// <param name="priority"> Access action priority </param>
        /// <param name="cancellation"> Access cancellation token </param>
        /// <param name="attemptsCount"> Retry on fail attempts count </param>
        /// <typeparam name="TResource"> Shared resource type</typeparam>
        /// <returns> Access action completion task </returns>
        /// <exception cref="ArgumentNullException"> Thrown if <paramref name="access" /> or <paramref name="queue" /> is NULL </exception>
        public static Task EnqueueAsyncAccess <TResource>(this IWorkQueue queue, IAsyncAccess <TResource> access, CancellationToken cancellation = default,
                                                          int attemptsCount = 1, int priority = 0)
            where TResource : notnull
        {
            _ = access ?? throw new ArgumentNullException(nameof(access));
            var work = CreateAsyncWork((provider, cancel) => provider.EnqueueAsyncAccess(access, cancel, attemptsCount, priority));

            return((queue ?? throw new ArgumentNullException(nameof(queue))) is IPriorityWorkQueue priorityQueue
            ? priorityQueue.EnqueueAsyncWork(work, priority, cancellation)
            : queue.EnqueueAsyncWork(work, cancellation));
        }
예제 #2
0
 /// <summary> Enqueue asynchronous access action into registered access queue with giver <paramref name="priority" /> (if supported) </summary>
 /// <param name="provider"> Service provider instance </param>
 /// <param name="access"> Access action instance </param>
 /// <param name="cancellation"> Access action cancellation token </param>
 /// <param name="attemptsCount"> Retry on fail attempts count </param>
 /// <param name="priority"> Access action priority </param>
 /// <typeparam name="TResource"> Shared resource type </typeparam>
 /// <typeparam name="TResult"> Access action result type </typeparam>
 /// <returns> Access action result task </returns>
 /// <exception cref="InvalidOperationException"> Thrown if no access queue for <typeparamref name="TResource" /> is registered </exception>
 /// <exception cref="ArgumentNullException"> Thrown if <paramref name="access" /> or <paramref name="provider" /> is NULL </exception>
 /// <seealso cref="IPriorityAccessQueue{TResource}.EnqueueAsyncAccess{TResult}(IAsyncAccess{TResource, TResult}, int, CancellationToken, int)" />
 public static Task <TResult> EnqueueAsyncAccess <TResource, TResult>(this IServiceProvider provider, IAsyncAccess <TResource, TResult> access,
                                                                      CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0)
     where TResource : notnull
 => (provider ?? throw new ArgumentNullException(nameof(provider))).Service <IPriorityAccessQueue <TResource> >()