Exemplo n.º 1
0
 /// <summary>
 /// Adds concurrent, non-exclusive work to the execution queue of the provided <see cref="AsyncReaderWriterLock"/>.
 /// </summary>
 /// <typeparam name="T">The result type.</typeparam>
 /// <param name="asyncReaderWriterLock">The <see cref="AsyncReaderWriterLock"/> to schedule work on.</param>
 /// <param name="workerObservable">The worker observable.</param>
 /// <param name="scheduler">The scheduler. If none is provided, <see cref="Scheduler.Default"/> is used.</param>
 /// <returns></returns>
 public static IObservable <T> AddConcurrentNonExclusiveWork <T>(this AsyncReaderWriterLock asyncReaderWriterLock, IObservable <T> workerObservable, IScheduler scheduler = null)
 {
     if (asyncReaderWriterLock == null)
     {
         throw new ArgumentNullException(nameof(asyncReaderWriterLock));
     }
     return(asyncReaderWriterLock.AcquireConcurrentReaderLock().PerformReaderWriterLockedWorkOnScheduler(workerObservable, scheduler));
 }
Exemplo n.º 2
0
        /// <summary>
        /// Adds concurrent, non-exclusive work to the execution queue of the provided <see cref="AsyncReaderWriterLock"/>.
        /// </summary>
        /// <typeparam name="T">The result type.</typeparam>
        /// <param name="asyncReaderWriterLock">The <see cref="AsyncReaderWriterLock"/> to schedule work on.</param>
        /// <param name="action">The action.</param>
        /// <param name="synchronizationContext">The synchronization context to execute the work on. If none is provided, <see cref="SynchronizationContext.Current"/> is used.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public static Task <T> AddConcurrentNonExclusiveWork <T>(this AsyncReaderWriterLock asyncReaderWriterLock, Func <CancellationToken, Task <T> > action, SynchronizationContext synchronizationContext = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (asyncReaderWriterLock == null)
            {
                throw new ArgumentNullException(nameof(asyncReaderWriterLock));
            }
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            return(asyncReaderWriterLock.AcquireConcurrentReaderLock().PerformReaderWriterLockedWorkOnSynchronizationContext(Observable.FromAsync(token => action.Invoke(CancellationTokenSource.CreateLinkedTokenSource(token, cancellationToken).Token)), synchronizationContext).ToTask(cancellationToken));
        }