/// <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)); }
/// <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)); }
/// <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)); }
/// <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)); }