Ejemplo n.º 1
0
        /// <summary>
        /// Adds exclusive, non-concurrent work to the execution queue of the provided <see cref="AsyncReaderWriterLock"/>.
        /// </summary>
        /// <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 <Unit> AddExclusiveWork(this AsyncReaderWriterLock asyncReaderWriterLock, IObservable <Unit> workerObservable, IScheduler scheduler = null)
        {
            if (asyncReaderWriterLock == null)
            {
                throw new ArgumentNullException(nameof(asyncReaderWriterLock));
            }

            return(asyncReaderWriterLock.AcquireExclusiveWriterLock().PerformReaderWriterLockedWorkOnScheduler(workerObservable, scheduler));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds exclusive, non-concurrent work to the execution queue of the provided <see cref="AsyncReaderWriterLock"/>.
        /// </summary>
        /// <param name="asyncReaderWriterLock">The <see cref="AsyncReaderWriterLock"/> to schedule work on.</param>
        /// <param name="action">The action.</param>
        /// <param name="synchronizationContext">The synchronization context.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public static Task AddExclusiveWork(this AsyncReaderWriterLock asyncReaderWriterLock, Func <CancellationToken, Task> 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.AcquireExclusiveWriterLock().PerformReaderWriterLockedWorkOnSynchronizationContext(Observable.FromAsync(token => action.Invoke(CancellationTokenSource.CreateLinkedTokenSource(token, cancellationToken).Token)), synchronizationContext).ToTask(cancellationToken));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds exclusive, non-concurrent work to the execution queue of the provided <see cref="AsyncReaderWriterLock"/>.
        /// </summary>
        /// <typeparam name="T"></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>
        /// <exception cref="System.ArgumentNullException">
        /// </exception>
        public static Task <T> AddExclusiveWork <T>(this AsyncReaderWriterLock asyncReaderWriterLock, Func <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.AcquireExclusiveWriterLock().PerformReaderWriterLockedWorkOnSynchronizationContext(Observable.FromAsync(action), synchronizationContext).ToTask(cancellationToken));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Adds exclusive, non-concurrent 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> AddExclusiveWork <T>(this AsyncReaderWriterLock asyncReaderWriterLock, IObservable <T> workerObservable, IScheduler scheduler = null)
 {
     return(asyncReaderWriterLock.AcquireExclusiveWriterLock().PerformReaderWriterLockedWorkOnScheduler(workerObservable, scheduler));
 }