diff --git a/src/AInq.Background.Abstraction/Interaction/WorkQueueAccessQueueInteraction.cs b/src/AInq.Background.Abstraction/Interaction/WorkQueueAccessQueueInteraction.cs index 82fbe79..2b7e539 100644 --- a/src/AInq.Background.Abstraction/Interaction/WorkQueueAccessQueueInteraction.cs +++ b/src/AInq.Background.Abstraction/Interaction/WorkQueueAccessQueueInteraction.cs @@ -36,7 +36,7 @@ public static Task EnqueueAccess(this IWorkQueue queue, IAccess EnqueueAccess(this IWorkQueue qu CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0) where TResource : notnull { - var work = CreateQueuedAccess(access ?? throw new ArgumentNullException(nameof(access)), attemptsCount, priority); + var work = CreateQueuedAccess(access ?? throw new ArgumentNullException(nameof(access)), priority, attemptsCount); return (queue ?? throw new ArgumentNullException(nameof(queue))) is IPriorityWorkQueue priorityQueue ? priorityQueue.EnqueueAsyncWork(work, priority, cancellation) : queue.EnqueueAsyncWork(work, cancellation); @@ -76,7 +76,7 @@ public static Task EnqueueAsyncAccess(this IWorkQueue queue, IAsyncAc int attemptsCount = 1, int priority = 0) where TResource : notnull { - var work = CreateQueuedAsyncAccess(asyncAccess ?? throw new ArgumentNullException(nameof(asyncAccess)), attemptsCount, priority); + var work = CreateQueuedAsyncAccess(asyncAccess ?? throw new ArgumentNullException(nameof(asyncAccess)), priority, attemptsCount); return (queue ?? throw new ArgumentNullException(nameof(queue))) is IPriorityWorkQueue priorityQueue ? priorityQueue.EnqueueAsyncWork(work, priority, cancellation) : queue.EnqueueAsyncWork(work, cancellation); @@ -96,7 +96,7 @@ public static Task EnqueueAsyncAccess(this IWorkQue CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0) where TResource : notnull { - var work = CreateQueuedAsyncAccess(asyncAccess ?? throw new ArgumentNullException(nameof(asyncAccess)), attemptsCount, priority); + var work = CreateQueuedAsyncAccess(asyncAccess ?? throw new ArgumentNullException(nameof(asyncAccess)), priority, attemptsCount); return (queue ?? throw new ArgumentNullException(nameof(queue))) is IPriorityWorkQueue priorityQueue ? priorityQueue.EnqueueAsyncWork(work, priority, cancellation) : queue.EnqueueAsyncWork(work, cancellation); @@ -120,7 +120,7 @@ public static Task EnqueueAccess(this IWorkQueue queue, Canc where TResource : notnull where TAccess : IAccess { - var work = CreateQueuedInjectedAccess(attemptsCount, priority); + var work = CreateQueuedInjectedAccess(priority, attemptsCount); return (queue ?? throw new ArgumentNullException(nameof(queue))) is IPriorityWorkQueue priorityQueue ? priorityQueue.EnqueueAsyncWork(work, priority, cancellation) : queue.EnqueueAsyncWork(work, cancellation); @@ -141,7 +141,7 @@ public static Task EnqueueAccess(this IWor where TResource : notnull where TAccess : IAccess { - var work = CreateQueuedInjectedAccess(attemptsCount, priority); + var work = CreateQueuedInjectedAccess(priority, attemptsCount); return (queue ?? throw new ArgumentNullException(nameof(queue))) is IPriorityWorkQueue priorityQueue ? priorityQueue.EnqueueAsyncWork(work, priority, cancellation) : queue.EnqueueAsyncWork(work, cancellation); @@ -161,7 +161,7 @@ public static Task EnqueueAsyncAccess(this IWorkQueue q where TResource : notnull where TAsyncAccess : IAsyncAccess { - var work = CreateQueuedInjectedAsyncAccess(attemptsCount, priority); + var work = CreateQueuedInjectedAsyncAccess(priority, attemptsCount); return (queue ?? throw new ArgumentNullException(nameof(queue))) is IPriorityWorkQueue priorityQueue ? priorityQueue.EnqueueAsyncWork(work, priority, cancellation) : queue.EnqueueAsyncWork(work, cancellation); @@ -182,7 +182,7 @@ public static Task EnqueueAsyncAccess where TResource : notnull where TAsyncAccess : IAsyncAccess { - var work = CreateQueuedInjectedAsyncAccess(attemptsCount, priority); + var work = CreateQueuedInjectedAsyncAccess(priority, attemptsCount); return (queue ?? throw new ArgumentNullException(nameof(queue))) is IPriorityWorkQueue priorityQueue ? priorityQueue.EnqueueAsyncWork(work, priority, cancellation) : queue.EnqueueAsyncWork(work, cancellation); diff --git a/src/AInq.Background.Scheduler.Abstraction/Interaction/WorkSchedulerWorkQueueInteraction.cs b/src/AInq.Background.Scheduler.Abstraction/Interaction/WorkSchedulerWorkQueueInteraction.cs index 734ad8c..17c9b31 100644 --- a/src/AInq.Background.Scheduler.Abstraction/Interaction/WorkSchedulerWorkQueueInteraction.cs +++ b/src/AInq.Background.Scheduler.Abstraction/Interaction/WorkSchedulerWorkQueueInteraction.cs @@ -35,7 +35,7 @@ public static class WorkSchedulerWorkQueueInteraction public static Task AddScheduledQueueWork(this IWorkScheduler scheduler, IWork work, TimeSpan delay, CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0) => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddScheduledAsyncWork( - CreateQueuedWork(work ?? throw new ArgumentNullException(nameof(work)), attemptsCount, priority), + CreateQueuedWork(work ?? throw new ArgumentNullException(nameof(work)), priority, attemptsCount), delay, cancellation); @@ -53,7 +53,7 @@ public static Task AddScheduledQueueWork(this IWorkScheduler scheduler, IWork wo public static Task AddScheduledQueueWork(this IWorkScheduler scheduler, IWork work, TimeSpan delay, CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0) => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddScheduledAsyncWork( - CreateQueuedWork(work ?? throw new ArgumentNullException(nameof(work)), attemptsCount, priority), + CreateQueuedWork(work ?? throw new ArgumentNullException(nameof(work)), priority, attemptsCount), delay, cancellation); @@ -70,7 +70,7 @@ public static Task AddScheduledQueueWork(this IWorkScheduler s public static Task AddScheduledAsyncQueueWork(this IWorkScheduler scheduler, IAsyncWork asyncWork, TimeSpan delay, CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0) => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddScheduledAsyncWork( - CreateQueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), attemptsCount, priority), + CreateQueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), priority, attemptsCount), delay, cancellation); @@ -88,7 +88,7 @@ public static Task AddScheduledAsyncQueueWork(this IWorkScheduler scheduler, IAs public static Task AddScheduledAsyncQueueWork(this IWorkScheduler scheduler, IAsyncWork asyncWork, TimeSpan delay, CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0) => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddScheduledAsyncWork( - CreateQueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), attemptsCount, priority), + CreateQueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), priority, attemptsCount), delay, cancellation); @@ -110,7 +110,7 @@ public static Task AddScheduledQueueWork(this IWorkScheduler scheduler, T int attemptsCount = 1, int priority = 0) where TWork : IWork => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))) - .AddScheduledAsyncWork(CreateQueuedInjectedWork(attemptsCount, priority), delay, cancellation); + .AddScheduledAsyncWork(CreateQueuedInjectedWork(priority, attemptsCount), delay, cancellation); /// Add delayed queued work to scheduler with given (if supported) /// Work scheduler instance @@ -127,7 +127,7 @@ public static Task AddScheduledQueueWork(this IWorkSche CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0) where TWork : IWork => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))) - .AddScheduledAsyncWork(CreateQueuedInjectedWork(attemptsCount, priority), delay, cancellation); + .AddScheduledAsyncWork(CreateQueuedInjectedWork(priority, attemptsCount), delay, cancellation); /// Add delayed queued asynchronous work to scheduler with given (if supported) /// Work scheduler instance @@ -143,7 +143,7 @@ public static Task AddScheduledAsyncQueueWork(this IWorkScheduler sc int attemptsCount = 1, int priority = 0) where TAsyncWork : IAsyncWork => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))) - .AddScheduledAsyncWork(CreateQueuedInjectedAsyncWork(attemptsCount, priority), delay, cancellation); + .AddScheduledAsyncWork(CreateQueuedInjectedAsyncWork(priority, attemptsCount), delay, cancellation); /// Add delayed queued asynchronous work to scheduler with given (if supported) /// Work scheduler instance @@ -160,7 +160,7 @@ public static Task AddScheduledAsyncQueueWork(this CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0) where TAsyncWork : IAsyncWork => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))) - .AddScheduledAsyncWork(CreateQueuedInjectedAsyncWork(attemptsCount, priority), delay, cancellation); + .AddScheduledAsyncWork(CreateQueuedInjectedAsyncWork(priority, attemptsCount), delay, cancellation); #endregion @@ -179,7 +179,7 @@ public static Task AddScheduledAsyncQueueWork(this public static Task AddScheduledQueueWork(this IWorkScheduler scheduler, IWork work, DateTime time, CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0) => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddScheduledAsyncWork( - CreateQueuedWork(work ?? throw new ArgumentNullException(nameof(work)), attemptsCount, priority), + CreateQueuedWork(work ?? throw new ArgumentNullException(nameof(work)), priority, attemptsCount), time, cancellation); @@ -197,7 +197,7 @@ public static Task AddScheduledQueueWork(this IWorkScheduler scheduler, IWork wo public static Task AddScheduledQueueWork(this IWorkScheduler scheduler, IWork work, DateTime time, CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0) => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddScheduledAsyncWork( - CreateQueuedWork(work ?? throw new ArgumentNullException(nameof(work)), attemptsCount, priority), + CreateQueuedWork(work ?? throw new ArgumentNullException(nameof(work)), priority, attemptsCount), time, cancellation); @@ -214,7 +214,7 @@ public static Task AddScheduledQueueWork(this IWorkScheduler s public static Task AddScheduledAsyncQueueWork(this IWorkScheduler scheduler, IAsyncWork asyncWork, DateTime time, CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0) => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddScheduledAsyncWork( - CreateQueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), attemptsCount, priority), + CreateQueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), priority, attemptsCount), time, cancellation); @@ -232,7 +232,7 @@ public static Task AddScheduledAsyncQueueWork(this IWorkScheduler scheduler, IAs public static Task AddScheduledAsyncQueueWork(this IWorkScheduler scheduler, IAsyncWork asyncWork, DateTime time, CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0) => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddScheduledAsyncWork( - CreateQueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), attemptsCount, priority), + CreateQueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), priority, attemptsCount), time, cancellation); @@ -254,7 +254,7 @@ public static Task AddScheduledQueueWork(this IWorkScheduler scheduler, D int attemptsCount = 1, int priority = 0) where TWork : IWork => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))) - .AddScheduledAsyncWork(CreateQueuedInjectedWork(attemptsCount, priority), time, cancellation); + .AddScheduledAsyncWork(CreateQueuedInjectedWork(priority, attemptsCount), time, cancellation); /// Add scheduled queued work to scheduler with given (if supported) /// Work scheduler instance @@ -271,7 +271,7 @@ public static Task AddScheduledQueueWork(this IWorkSche CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0) where TWork : IWork => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))) - .AddScheduledAsyncWork(CreateQueuedInjectedWork(attemptsCount, priority), time, cancellation); + .AddScheduledAsyncWork(CreateQueuedInjectedWork(priority, attemptsCount), time, cancellation); /// Add scheduled queued asynchronous work to scheduler with given (if supported) /// Work scheduler instance @@ -287,7 +287,7 @@ public static Task AddScheduledAsyncQueueWork(this IWorkScheduler sc int attemptsCount = 1, int priority = 0) where TAsyncWork : IAsyncWork => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))) - .AddScheduledAsyncWork(CreateQueuedInjectedAsyncWork(attemptsCount, priority), time, cancellation); + .AddScheduledAsyncWork(CreateQueuedInjectedAsyncWork(priority, attemptsCount), time, cancellation); /// Add scheduled queued asynchronous work to scheduler with given (if supported) /// Work scheduler instance @@ -304,7 +304,7 @@ public static Task AddScheduledAsyncQueueWork(this CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0) where TAsyncWork : IAsyncWork => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))) - .AddScheduledAsyncWork(CreateQueuedInjectedAsyncWork(attemptsCount, priority), time, cancellation); + .AddScheduledAsyncWork(CreateQueuedInjectedAsyncWork(priority, attemptsCount), time, cancellation); #endregion @@ -325,7 +325,7 @@ public static Task AddScheduledAsyncQueueWork(this public static IObservable> AddCronQueueWork(this IWorkScheduler scheduler, IWork work, string cronExpression, CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0, int execCount = -1) => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddCronAsyncWork( - CreateQueuedWork(work ?? throw new ArgumentNullException(nameof(work)), attemptsCount, priority), + CreateQueuedWork(work ?? throw new ArgumentNullException(nameof(work)), priority, attemptsCount), cronExpression ?? throw new ArgumentNullException(nameof(cronExpression)), cancellation, execCount); @@ -346,7 +346,7 @@ public static IObservable> AddCronQueueWork(this IWorkScheduler public static IObservable> AddCronQueueWork(this IWorkScheduler scheduler, IWork work, string cronExpression, CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0, int execCount = -1) => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddCronAsyncWork( - CreateQueuedWork(work ?? throw new ArgumentNullException(nameof(work)), attemptsCount, priority), + CreateQueuedWork(work ?? throw new ArgumentNullException(nameof(work)), priority, attemptsCount), cronExpression ?? throw new ArgumentNullException(nameof(cronExpression)), cancellation, execCount); @@ -366,7 +366,7 @@ public static IObservable> AddCronQueueWork(this IWorkSche public static IObservable> AddCronAsyncQueueWork(this IWorkScheduler scheduler, IAsyncWork asyncWork, string cronExpression, CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0, int execCount = -1) => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddCronAsyncWork( - CreateQueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), attemptsCount, priority), + CreateQueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), priority, attemptsCount), cronExpression ?? throw new ArgumentNullException(nameof(cronExpression)), cancellation, execCount); @@ -387,7 +387,7 @@ public static IObservable> AddCronAsyncQueueWork(this IWorkSche public static IObservable> AddCronAsyncQueueWork(this IWorkScheduler scheduler, IAsyncWork asyncWork, string cronExpression, CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0, int execCount = -1) => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddCronAsyncWork( - CreateQueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), attemptsCount, priority), + CreateQueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), priority, attemptsCount), cronExpression ?? throw new ArgumentNullException(nameof(cronExpression)), cancellation, execCount); @@ -412,7 +412,7 @@ public static IObservable> AddCronQueueWork(this IWorkSc CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0, int execCount = -1) where TWork : IWork => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddCronAsyncWork( - CreateQueuedInjectedWork(attemptsCount, priority), + CreateQueuedInjectedWork(priority, attemptsCount), cronExpression ?? throw new ArgumentNullException(nameof(cronExpression)), cancellation, execCount); @@ -434,7 +434,7 @@ public static IObservable> AddCronQueueWork(this IW CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0, int execCount = -1) where TWork : IWork => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddCronAsyncWork( - CreateQueuedInjectedWork(attemptsCount, priority), + CreateQueuedInjectedWork(priority, attemptsCount), cronExpression ?? throw new ArgumentNullException(nameof(cronExpression)), cancellation, execCount); @@ -455,7 +455,7 @@ public static IObservable> AddCronAsyncQueueWork(th CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0, int execCount = -1) where TAsyncWork : IAsyncWork => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddCronAsyncWork( - CreateQueuedInjectedAsyncWork(attemptsCount, priority), + CreateQueuedInjectedAsyncWork(priority, attemptsCount), cronExpression ?? throw new ArgumentNullException(nameof(cronExpression)), cancellation, execCount); @@ -477,7 +477,7 @@ public static IObservable> AddCronAsyncQueueWork => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddCronAsyncWork( - CreateQueuedInjectedAsyncWork(attemptsCount, priority), + CreateQueuedInjectedAsyncWork(priority, attemptsCount), cronExpression ?? throw new ArgumentNullException(nameof(cronExpression)), cancellation, execCount); @@ -501,7 +501,7 @@ public static IObservable> AddCronAsyncQueueWork> AddRepeatedQueueWork(this IWorkScheduler scheduler, IWork work, DateTime starTime, TimeSpan repeatDelay, CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0, int execCount = -1) => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddRepeatedAsyncWork( - CreateQueuedWork(work ?? throw new ArgumentNullException(nameof(work)), attemptsCount, priority), + CreateQueuedWork(work ?? throw new ArgumentNullException(nameof(work)), priority, attemptsCount), starTime, repeatDelay, cancellation, @@ -523,7 +523,7 @@ public static IObservable> AddRepeatedQueueWork(this IWorkSched public static IObservable> AddRepeatedQueueWork(this IWorkScheduler scheduler, IWork work, DateTime starTime, TimeSpan repeatDelay, CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0, int execCount = -1) => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddRepeatedAsyncWork( - CreateQueuedWork(work ?? throw new ArgumentNullException(nameof(work)), attemptsCount, priority), + CreateQueuedWork(work ?? throw new ArgumentNullException(nameof(work)), priority, attemptsCount), starTime, repeatDelay, cancellation, @@ -544,7 +544,7 @@ public static IObservable> AddRepeatedQueueWork(this IWork public static IObservable> AddRepeatedAsyncQueueWork(this IWorkScheduler scheduler, IAsyncWork asyncWork, DateTime starTime, TimeSpan repeatDelay, CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0, int execCount = -1) => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddRepeatedAsyncWork( - CreateQueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), attemptsCount, priority), + CreateQueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), priority, attemptsCount), starTime, repeatDelay, cancellation, @@ -567,7 +567,7 @@ public static IObservable> AddRepeatedAsyncQueueWork(this DateTime starTime, TimeSpan repeatDelay, CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0, int execCount = -1) => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddRepeatedAsyncWork( - CreateQueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), attemptsCount, priority), + CreateQueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), priority, attemptsCount), starTime, repeatDelay, cancellation, @@ -593,7 +593,7 @@ public static IObservable> AddRepeatedQueueWork(this IWo CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0, int execCount = -1) where TWork : IWork => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))) - .AddRepeatedAsyncWork(CreateQueuedInjectedWork(attemptsCount, priority), starTime, repeatDelay, cancellation, execCount); + .AddRepeatedAsyncWork(CreateQueuedInjectedWork(priority, attemptsCount), starTime, repeatDelay, cancellation, execCount); /// Add repeated queued work to scheduler with given (if supported) /// Work Scheduler instance @@ -612,7 +612,7 @@ public static IObservable> AddRepeatedQueueWork(thi TimeSpan repeatDelay, CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0, int execCount = -1) where TWork : IWork => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddRepeatedAsyncWork( - CreateQueuedInjectedWork(attemptsCount, priority), + CreateQueuedInjectedWork(priority, attemptsCount), starTime, repeatDelay, cancellation, @@ -634,7 +634,7 @@ public static IObservable> AddRepeatedAsyncQueueWork (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddRepeatedAsyncWork( - CreateQueuedInjectedAsyncWork(attemptsCount, priority), + CreateQueuedInjectedAsyncWork(priority, attemptsCount), starTime, repeatDelay, cancellation, @@ -657,7 +657,7 @@ public static IObservable> AddRepeatedAsyncQueueWork => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddRepeatedAsyncWork( - CreateQueuedInjectedAsyncWork(attemptsCount, priority), + CreateQueuedInjectedAsyncWork(priority, attemptsCount), starTime, repeatDelay, cancellation, @@ -682,7 +682,7 @@ public static IObservable> AddRepeatedAsyncQueueWork> AddRepeatedQueueWork(this IWorkScheduler scheduler, IWork work, TimeSpan startDelay, TimeSpan repeatDelay, CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0, int execCount = -1) => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddRepeatedAsyncWork( - CreateQueuedWork(work ?? throw new ArgumentNullException(nameof(work)), attemptsCount, priority), + CreateQueuedWork(work ?? throw new ArgumentNullException(nameof(work)), priority, attemptsCount), startDelay, repeatDelay, cancellation, @@ -704,7 +704,7 @@ public static IObservable> AddRepeatedQueueWork(this IWorkSched public static IObservable> AddRepeatedQueueWork(this IWorkScheduler scheduler, IWork work, TimeSpan startDelay, TimeSpan repeatDelay, CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0, int execCount = -1) => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddRepeatedAsyncWork( - CreateQueuedWork(work ?? throw new ArgumentNullException(nameof(work)), attemptsCount, priority), + CreateQueuedWork(work ?? throw new ArgumentNullException(nameof(work)), priority, attemptsCount), startDelay, repeatDelay, cancellation, @@ -725,7 +725,7 @@ public static IObservable> AddRepeatedQueueWork(this IWork public static IObservable> AddRepeatedAsyncQueueWork(this IWorkScheduler scheduler, IAsyncWork asyncWork, TimeSpan startDelay, TimeSpan repeatDelay, CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0, int execCount = -1) => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddRepeatedAsyncWork( - CreateQueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), attemptsCount, priority), + CreateQueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), priority, attemptsCount), startDelay, repeatDelay, cancellation, @@ -748,7 +748,7 @@ public static IObservable> AddRepeatedAsyncQueueWork(this TimeSpan startDelay, TimeSpan repeatDelay, CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0, int execCount = -1) => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddRepeatedAsyncWork( - CreateQueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), attemptsCount, priority), + CreateQueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), priority, attemptsCount), startDelay, repeatDelay, cancellation, @@ -774,7 +774,7 @@ public static IObservable> AddRepeatedQueueWork(this IWo CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0, int execCount = -1) where TWork : IWork => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))) - .AddRepeatedAsyncWork(CreateQueuedInjectedWork(attemptsCount, priority), startDelay, repeatDelay, cancellation, execCount); + .AddRepeatedAsyncWork(CreateQueuedInjectedWork(priority, attemptsCount), startDelay, repeatDelay, cancellation, execCount); /// Add repeated queued work to scheduler with given (if supported) /// Work Scheduler instance @@ -793,7 +793,7 @@ public static IObservable> AddRepeatedQueueWork(thi TimeSpan repeatDelay, CancellationToken cancellation = default, int attemptsCount = 1, int priority = 0, int execCount = -1) where TWork : IWork => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddRepeatedAsyncWork( - CreateQueuedInjectedWork(attemptsCount, priority), + CreateQueuedInjectedWork(priority, attemptsCount), startDelay, repeatDelay, cancellation, @@ -815,7 +815,7 @@ public static IObservable> AddRepeatedAsyncQueueWork (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddRepeatedAsyncWork( - CreateQueuedInjectedAsyncWork(attemptsCount, priority), + CreateQueuedInjectedAsyncWork(priority, attemptsCount), startDelay, repeatDelay, cancellation, @@ -838,7 +838,7 @@ public static IObservable> AddRepeatedAsyncQueueWork => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddRepeatedAsyncWork( - CreateQueuedInjectedAsyncWork(attemptsCount, priority), + CreateQueuedInjectedAsyncWork(priority, attemptsCount), startDelay, repeatDelay, cancellation, diff --git a/src/AInq.Background.Scheduler/Managers/WorkSchedulerManager.cs b/src/AInq.Background.Scheduler/Managers/WorkSchedulerManager.cs index 1ee46d4..ed5e729 100644 --- a/src/AInq.Background.Scheduler/Managers/WorkSchedulerManager.cs +++ b/src/AInq.Background.Scheduler/Managers/WorkSchedulerManager.cs @@ -37,9 +37,9 @@ Task IWorkSchedulerManager.WaitForNewTaskAsync(CancellationToken cancellation) var works = Interlocked.Exchange(ref _works, new ConcurrentBag()); DateTime? next = null; while (!works.IsEmpty) - if (works.TryTake(out var work) && !work.IsCanceled && work.NextScheduledTime.HasValue) + if (works.TryTake(out var work) && work is {IsCanceled: false, NextScheduledTime: not null}) { - if (next == null || work.NextScheduledTime!.Value < next.Value) + if (next == null || work.NextScheduledTime.Value < next.Value) next = work.NextScheduledTime; _works.Add(work); } @@ -52,9 +52,9 @@ ILookup IWorkSchedulerManager.GetUpcomingTasks( var upcoming = new LinkedList(); var time = DateTime.Now.Add(horizon); while (!works.IsEmpty) - if (works.TryTake(out var work) && !work.IsCanceled && work.NextScheduledTime.HasValue) + if (works.TryTake(out var work) && work is {IsCanceled: false, NextScheduledTime: not null}) { - if (work.NextScheduledTime!.Value <= time) + if (work.NextScheduledTime.Value <= time) upcoming.AddLast(work); else _works.Add(work); } diff --git a/src/AInq.Background.Scheduler/Wrappers/CronWorkWrapperFactory.cs b/src/AInq.Background.Scheduler/Wrappers/CronWorkWrapperFactory.cs index f6323d5..f031495 100644 --- a/src/AInq.Background.Scheduler/Wrappers/CronWorkWrapperFactory.cs +++ b/src/AInq.Background.Scheduler/Wrappers/CronWorkWrapperFactory.cs @@ -123,7 +123,7 @@ internal CronTaskWrapper(IAsyncWork asyncWork, CronExpression cron, Cancellation _cron = cron; _innerCancellation = innerCancellation; _execCount = execCount; - _cancellationRegistration = _innerCancellation.Register(() => _subject.OnCompleted(), false); + _cancellationRegistration = _innerCancellation.Register(_subject.OnCompleted, false); } internal CronTaskWrapper(IWork work, CronExpression cron, CancellationToken innerCancellation, int execCount) @@ -133,7 +133,7 @@ internal CronTaskWrapper(IWork work, CronExpression cron, CancellationToken inne _cron = cron; _innerCancellation = innerCancellation; _execCount = execCount; - _cancellationRegistration = _innerCancellation.Register(() => _subject.OnCompleted(), false); + _cancellationRegistration = _innerCancellation.Register(_subject.OnCompleted, false); } internal IObservable> WorkObservable => _subject; @@ -170,7 +170,11 @@ async Task IScheduledTaskWrapper.ExecuteAsync(IServiceProvider provider, I if (_cron.GetNextOccurrence(DateTime.UtcNow, TimeZoneInfo.Local).HasValue && _execCount != 0) return true; _subject.OnCompleted(); - _cancellationRegistration.Dispose(); +#if NETSTANDARD2_0 + _cancellationRegistration.Dispose(); +#else + await _cancellationRegistration.DisposeAsync().ConfigureAwait(false); +#endif _cancellationRegistration = default; return false; } @@ -193,7 +197,7 @@ internal CronTaskWrapper(IAsyncWork asyncWork, CronExpression cron, Can _cron = cron; _innerCancellation = innerCancellation; _execCount = execCount; - _cancellationRegistration = _innerCancellation.Register(() => _subject.OnCompleted(), false); + _cancellationRegistration = _innerCancellation.Register(_subject.OnCompleted, false); } internal CronTaskWrapper(IWork work, CronExpression cron, CancellationToken innerCancellation, int execCount) @@ -203,7 +207,7 @@ internal CronTaskWrapper(IWork work, CronExpression cron, CancellationT _cron = cron; _innerCancellation = innerCancellation; _execCount = execCount; - _cancellationRegistration = _innerCancellation.Register(() => _subject.OnCompleted(), false); + _cancellationRegistration = _innerCancellation.Register(_subject.OnCompleted, false); } internal IObservable> WorkObservable => _subject; @@ -240,7 +244,11 @@ async Task IScheduledTaskWrapper.ExecuteAsync(IServiceProvider provider, I if (_cron.GetNextOccurrence(DateTime.UtcNow, TimeZoneInfo.Local).HasValue && _execCount != 0) return true; _subject.OnCompleted(); - _cancellationRegistration.Dispose(); +#if NETSTANDARD2_0 + _cancellationRegistration.Dispose(); +#else + await _cancellationRegistration.DisposeAsync().ConfigureAwait(false); +#endif _cancellationRegistration = default; return false; } diff --git a/src/AInq.Background.Scheduler/Wrappers/RepeatedWorkWrapperFactory.cs b/src/AInq.Background.Scheduler/Wrappers/RepeatedWorkWrapperFactory.cs index 5fffbfc..9e68d69 100644 --- a/src/AInq.Background.Scheduler/Wrappers/RepeatedWorkWrapperFactory.cs +++ b/src/AInq.Background.Scheduler/Wrappers/RepeatedWorkWrapperFactory.cs @@ -146,7 +146,7 @@ internal RepeatedTaskWrapper(IAsyncWork asyncWork, DateTime startTime, TimeSpan _repeatDelay = repeatDelay; while (_nextScheduledTime < DateTime.Now) _nextScheduledTime += _repeatDelay; _execCount = execCount; - _cancellationRegistration = _innerCancellation.Register(() => _subject.OnCompleted(), false); + _cancellationRegistration = _innerCancellation.Register(_subject.OnCompleted, false); } internal RepeatedTaskWrapper(IWork work, DateTime startTime, TimeSpan repeatDelay, CancellationToken innerCancellation, int execCount) @@ -158,7 +158,7 @@ internal RepeatedTaskWrapper(IWork work, DateTime startTime, TimeSpan repeatDela _repeatDelay = repeatDelay; while (_nextScheduledTime < DateTime.Now) _nextScheduledTime += _repeatDelay; _execCount = execCount; - _cancellationRegistration = _innerCancellation.Register(() => _subject.OnCompleted(), false); + _cancellationRegistration = _innerCancellation.Register(_subject.OnCompleted, false); } internal IObservable> WorkObservable => _subject; @@ -196,7 +196,11 @@ async Task IScheduledTaskWrapper.ExecuteAsync(IServiceProvider provider, I if (_execCount != 0) return true; _subject.OnCompleted(); - _cancellationRegistration.Dispose(); +#if NETSTANDARD2_0 + _cancellationRegistration.Dispose(); +#else + await _cancellationRegistration.DisposeAsync().ConfigureAwait(false); +#endif _cancellationRegistration = default; return false; } @@ -223,7 +227,7 @@ internal RepeatedTaskWrapper(IAsyncWork asyncWork, DateTime startTime, _repeatDelay = repeatDelay; while (_nextScheduledTime < DateTime.Now) _nextScheduledTime += _repeatDelay; _execCount = execCount; - _cancellationRegistration = _innerCancellation.Register(() => _subject.OnCompleted(), false); + _cancellationRegistration = _innerCancellation.Register(_subject.OnCompleted, false); } internal RepeatedTaskWrapper(IWork work, DateTime startTime, TimeSpan repeatDelay, CancellationToken innerCancellation, @@ -236,7 +240,7 @@ internal RepeatedTaskWrapper(IWork work, DateTime startTime, TimeSpan r _repeatDelay = repeatDelay; while (_nextScheduledTime < DateTime.Now) _nextScheduledTime += _repeatDelay; _execCount = execCount; - _cancellationRegistration = _innerCancellation.Register(() => _subject.OnCompleted(), false); + _cancellationRegistration = _innerCancellation.Register(_subject.OnCompleted, false); } internal IObservable> WorkObservable => _subject; @@ -274,7 +278,11 @@ async Task IScheduledTaskWrapper.ExecuteAsync(IServiceProvider provider, I if (_execCount != 0) return true; _subject.OnCompleted(); - _cancellationRegistration.Dispose(); +#if NETSTANDARD2_0 + _cancellationRegistration.Dispose(); +#else + await _cancellationRegistration.DisposeAsync().ConfigureAwait(false); +#endif _cancellationRegistration = default; return false; } diff --git a/src/AInq.Background.Scheduler/Wrappers/ScheduledWorkWrapperFactory.cs b/src/AInq.Background.Scheduler/Wrappers/ScheduledWorkWrapperFactory.cs index 89b5560..dddf842 100644 --- a/src/AInq.Background.Scheduler/Wrappers/ScheduledWorkWrapperFactory.cs +++ b/src/AInq.Background.Scheduler/Wrappers/ScheduledWorkWrapperFactory.cs @@ -143,7 +143,11 @@ async Task IScheduledTaskWrapper.ExecuteAsync(IServiceProvider provider, I _completion.TrySetException(ex); } _nextScheduledTime = null; - _cancellationRegistration.Dispose(); +#if NETSTANDARD2_0 + _cancellationRegistration.Dispose(); +#else + await _cancellationRegistration.DisposeAsync().ConfigureAwait(false); +#endif _cancellationRegistration = default; return false; } @@ -203,7 +207,11 @@ async Task IScheduledTaskWrapper.ExecuteAsync(IServiceProvider provider, I _completion.TrySetException(ex); } _nextScheduledTime = null; - _cancellationRegistration.Dispose(); +#if NETSTANDARD2_0 + _cancellationRegistration.Dispose(); +#else + await _cancellationRegistration.DisposeAsync().ConfigureAwait(false); +#endif _cancellationRegistration = default; return false; } diff --git a/src/AInq.Background/Helpers/DisposableHelper.cs b/src/AInq.Background/Helpers/DisposableHelper.cs new file mode 100644 index 0000000..6624135 --- /dev/null +++ b/src/AInq.Background/Helpers/DisposableHelper.cs @@ -0,0 +1,29 @@ +// Copyright 2020-2023 Anton Andryushchenko +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace AInq.Background.Helpers; + +internal static class DisposableHelper +{ + public static ValueTask TryDisposeAsync(this object? item) + { + if (item is IAsyncDisposable asyncDisposable) return asyncDisposable.DisposeAsync(); + (item as IDisposable)?.Dispose(); +#if NETSTANDARD + return new ValueTask(); +#else + return ValueTask.CompletedTask; +#endif + } +} diff --git a/src/AInq.Background/Processors/MultipleOneTimeProcessor.cs b/src/AInq.Background/Processors/MultipleOneTimeProcessor.cs index 05a266a..64c1253 100644 --- a/src/AInq.Background/Processors/MultipleOneTimeProcessor.cs +++ b/src/AInq.Background/Processors/MultipleOneTimeProcessor.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using AInq.Background.Helpers; using AInq.Background.Managers; using AInq.Background.Wrappers; @@ -68,7 +69,7 @@ private async void Execute(ITaskWrapper task, TMetadata metadata, ITa logger.LogError(ex, "Error starting stoppable argument {Argument}", argument); manager.RevertTask(task, metadata); _semaphore.Release(); - (argument as IDisposable)?.Dispose(); + await argument.TryDisposeAsync().ConfigureAwait(false); return; } if (!await task.ExecuteAsync(argument, provider, logger, cancellation).ConfigureAwait(false)) @@ -84,8 +85,7 @@ private async void Execute(ITaskWrapper task, TMetadata metadata, ITa } finally { - _semaphore.Release(); - (argument as IDisposable)?.Dispose(); + await argument.TryDisposeAsync().ConfigureAwait(false); } } } diff --git a/src/AInq.Background/Processors/MultipleReusableProcessor.cs b/src/AInq.Background/Processors/MultipleReusableProcessor.cs index 10ab4ec..8d6a400 100644 --- a/src/AInq.Background/Processors/MultipleReusableProcessor.cs +++ b/src/AInq.Background/Processors/MultipleReusableProcessor.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using AInq.Background.Helpers; using AInq.Background.Managers; using AInq.Background.Wrappers; @@ -87,7 +88,7 @@ private async Task Execute(TArgument argument, ITaskWrapper task, TMe manager.RevertTask(task, metadata); Interlocked.Decrement(ref _currentArgumentCount); _reset.Set(); - (argument as IDisposable)?.Dispose(); + await argument.TryDisposeAsync().ConfigureAwait(false); return; } if (!await task.ExecuteAsync(argument, provider, logger, cancellation).ConfigureAwait(false)) @@ -129,7 +130,7 @@ private static async void UtilizeArgument(TArgument argument, ILogger logger, Ca } finally { - (argument as IDisposable)?.Dispose(); + await argument.TryDisposeAsync().ConfigureAwait(false); } } } diff --git a/src/AInq.Background/Processors/MultipleStaticProcessor.cs b/src/AInq.Background/Processors/MultipleStaticProcessor.cs index bd9e40a..9bce316 100644 --- a/src/AInq.Background/Processors/MultipleStaticProcessor.cs +++ b/src/AInq.Background/Processors/MultipleStaticProcessor.cs @@ -12,12 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +using AInq.Background.Helpers; using AInq.Background.Managers; using AInq.Background.Wrappers; namespace AInq.Background.Processors; -internal sealed class MultipleStaticProcessor : ITaskProcessor, IDisposable +internal sealed class MultipleStaticProcessor : ITaskProcessor, IDisposable, IAsyncDisposable { private readonly ConcurrentBag _active = new(); private readonly ConcurrentBag _inactive; @@ -35,6 +36,12 @@ void IDisposable.Dispose() (argument as IDisposable)?.Dispose(); } + async ValueTask IAsyncDisposable.DisposeAsync() + { + while (_active.TryTake(out var argument) || _inactive.TryTake(out argument)) + await argument.TryDisposeAsync().ConfigureAwait(false); + } + async Task ITaskProcessor.ProcessPendingTasksAsync(ITaskManager manager, IServiceProvider provider, ILogger logger, CancellationToken cancellation) { diff --git a/src/AInq.Background/Processors/SingleOneTimeProcessor.cs b/src/AInq.Background/Processors/SingleOneTimeProcessor.cs index cec556f..41461a4 100644 --- a/src/AInq.Background/Processors/SingleOneTimeProcessor.cs +++ b/src/AInq.Background/Processors/SingleOneTimeProcessor.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using AInq.Background.Helpers; using AInq.Background.Managers; namespace AInq.Background.Processors; @@ -53,7 +54,7 @@ async Task ITaskProcessor.ProcessPendingTasksAsync(ITaskMa { logger.LogError(ex, "Error starting stoppable argument {Argument}", argument); manager.RevertTask(task, metadata); - (argument as IDisposable)?.Dispose(); + await argument.TryDisposeAsync().ConfigureAwait(false); continue; } if (!await task.ExecuteAsync(argument, provider, logger, cancellation).ConfigureAwait(false)) @@ -75,7 +76,7 @@ private static async void UtilizeArgument(TArgument argument, ILogger logger, Ca } finally { - (argument as IDisposable)?.Dispose(); + await argument.TryDisposeAsync().ConfigureAwait(false); } } } diff --git a/src/AInq.Background/Processors/SingleReusableProcessor.cs b/src/AInq.Background/Processors/SingleReusableProcessor.cs index 2f531ca..06d0e13 100644 --- a/src/AInq.Background/Processors/SingleReusableProcessor.cs +++ b/src/AInq.Background/Processors/SingleReusableProcessor.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using AInq.Background.Helpers; using AInq.Background.Managers; namespace AInq.Background.Processors; @@ -42,25 +43,25 @@ async Task ITaskProcessor.ProcessPendingTasksAsync(ITaskMa } try { - if (argument is IStartStoppable {IsActive: false} startStoppable) + if (argument is IStartStoppable { IsActive: false } startStoppable) await startStoppable.ActivateAsync(cancellation).ConfigureAwait(false); } catch (Exception ex) { logger.LogError(ex, "Error starting stoppable argument {Argument}", argument); - (argument as IDisposable)?.Dispose(); + await argument.TryDisposeAsync().ConfigureAwait(false); return; } while (manager.HasTask && !cancellation.IsCancellationRequested) { - if (argument is IStartStoppable {IsActive: false}) break; + if (argument is IStartStoppable { IsActive: false }) break; var (task, metadata) = manager.GetTask(); if (task == null) continue; if (!await task.ExecuteAsync(argument, provider, logger, cancellation).ConfigureAwait(false)) manager.RevertTask(task, metadata); try { - if (argument is IThrottling {Timeout.Ticks: > 0} throttling) + if (argument is IThrottling { Timeout.Ticks: > 0 } throttling) await Task.Delay(throttling.Timeout, cancellation).ConfigureAwait(false); } catch (OperationCanceledException) @@ -75,7 +76,7 @@ private static async void UtilizeArgument(TArgument argument, ILogger logger, Ca { try { - if (argument is IStartStoppable {IsActive: true} startStoppable) + if (argument is IStartStoppable { IsActive: true } startStoppable) await startStoppable.DeactivateAsync(cancellation).ConfigureAwait(false); } catch (Exception ex) @@ -84,7 +85,7 @@ private static async void UtilizeArgument(TArgument argument, ILogger logger, Ca } finally { - (argument as IDisposable)?.Dispose(); + await argument.TryDisposeAsync().ConfigureAwait(false); } } } diff --git a/src/AInq.Background/Processors/SingleStaticProcessor.cs b/src/AInq.Background/Processors/SingleStaticProcessor.cs index 1af587d..2f7af06 100644 --- a/src/AInq.Background/Processors/SingleStaticProcessor.cs +++ b/src/AInq.Background/Processors/SingleStaticProcessor.cs @@ -12,11 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +using AInq.Background.Helpers; using AInq.Background.Managers; namespace AInq.Background.Processors; -internal sealed class SingleStaticProcessor : ITaskProcessor, IDisposable +internal sealed class SingleStaticProcessor : ITaskProcessor, IDisposable, IAsyncDisposable { private readonly TArgument _argument; @@ -26,6 +27,9 @@ internal SingleStaticProcessor(TArgument argument) void IDisposable.Dispose() => (_argument as IDisposable)?.Dispose(); + async ValueTask IAsyncDisposable.DisposeAsync() + => await _argument.TryDisposeAsync().ConfigureAwait(false); + async Task ITaskProcessor.ProcessPendingTasksAsync(ITaskManager manager, IServiceProvider provider, ILogger logger, CancellationToken cancellation) { diff --git a/src/AInq.Background/Wrappers/AccessWrapperFactory.cs b/src/AInq.Background/Wrappers/AccessWrapperFactory.cs index b66a5fe..9c9c9e7 100644 --- a/src/AInq.Background/Wrappers/AccessWrapperFactory.cs +++ b/src/AInq.Background/Wrappers/AccessWrapperFactory.cs @@ -126,7 +126,11 @@ async Task ITaskWrapper.ExecuteAsync(TResource argument, IServi if (_attemptsRemain < 1) { _completion.TrySetException(new InvalidOperationException("No attempts left")); +#if NETSTANDARD2_0 _cancellationRegistration.Dispose(); +#else + await _cancellationRegistration.DisposeAsync().ConfigureAwait(false); +#endif _cancellationRegistration = default; return true; } @@ -159,7 +163,11 @@ async Task ITaskWrapper.ExecuteAsync(TResource argument, IServi return false; _completion.TrySetException(ex); } - _cancellationRegistration.Dispose(); +#if NETSTANDARD2_0 + _cancellationRegistration.Dispose(); +#else + await _cancellationRegistration.DisposeAsync().ConfigureAwait(false); +#endif _cancellationRegistration = default; return true; } @@ -204,7 +212,11 @@ async Task ITaskWrapper.ExecuteAsync(TResource argument, IServi if (_attemptsRemain < 1) { _completion.TrySetException(new InvalidOperationException("No attempts left")); +#if NETSTANDARD2_0 _cancellationRegistration.Dispose(); +#else + await _cancellationRegistration.DisposeAsync().ConfigureAwait(false); +#endif _cancellationRegistration = default; return true; } @@ -236,7 +248,11 @@ async Task ITaskWrapper.ExecuteAsync(TResource argument, IServi return false; _completion.TrySetException(ex); } - _cancellationRegistration.Dispose(); +#if NETSTANDARD2_0 + _cancellationRegistration.Dispose(); +#else + await _cancellationRegistration.DisposeAsync().ConfigureAwait(false); +#endif _cancellationRegistration = default; return true; } diff --git a/src/AInq.Background/Wrappers/ConveyorDataWrapperFactory.cs b/src/AInq.Background/Wrappers/ConveyorDataWrapperFactory.cs index 1868f8e..72c5dca 100644 --- a/src/AInq.Background/Wrappers/ConveyorDataWrapperFactory.cs +++ b/src/AInq.Background/Wrappers/ConveyorDataWrapperFactory.cs @@ -61,7 +61,11 @@ async Task ITaskWrapper>.ExecuteAsync(ICo if (_attemptsRemain < 1) { _completion.TrySetException(new InvalidOperationException("No attempts left")); +#if NETSTANDARD2_0 _cancellationRegistration.Dispose(); +#else + await _cancellationRegistration.DisposeAsync().ConfigureAwait(false); +#endif _cancellationRegistration = default; return true; } @@ -94,7 +98,11 @@ async Task ITaskWrapper>.ExecuteAsync(ICo return false; _completion.TrySetException(ex); } - _cancellationRegistration.Dispose(); +#if NETSTANDARD2_0 + _cancellationRegistration.Dispose(); +#else + await _cancellationRegistration.DisposeAsync().ConfigureAwait(false); +#endif _cancellationRegistration = default; return true; } diff --git a/src/AInq.Background/Wrappers/WorkWrapperFactory.cs b/src/AInq.Background/Wrappers/WorkWrapperFactory.cs index 8885377..806ddfe 100644 --- a/src/AInq.Background/Wrappers/WorkWrapperFactory.cs +++ b/src/AInq.Background/Wrappers/WorkWrapperFactory.cs @@ -111,7 +111,11 @@ internal WorkWrapper(IWork work, int attemptsCount, CancellationToken innerCance if (_attemptsRemain < 1) { _completion.TrySetException(new InvalidOperationException("No attempts left")); +#if NETSTANDARD2_0 _cancellationRegistration.Dispose(); +#else + await _cancellationRegistration.DisposeAsync().ConfigureAwait(false); +#endif _cancellationRegistration = default; return true; } @@ -142,7 +146,11 @@ internal WorkWrapper(IWork work, int attemptsCount, CancellationToken innerCance return false; _completion.TrySetException(ex); } - _cancellationRegistration.Dispose(); +#if NETSTANDARD2_0 + _cancellationRegistration.Dispose(); +#else + await _cancellationRegistration.DisposeAsync().ConfigureAwait(false); +#endif _cancellationRegistration = default; return true; } @@ -186,7 +194,11 @@ internal WorkWrapper(IWork work, int attemptsCount, CancellationToken i if (_attemptsRemain < 1) { _completion.TrySetException(new InvalidOperationException("No attempts left")); +#if NETSTANDARD2_0 _cancellationRegistration.Dispose(); +#else + await _cancellationRegistration.DisposeAsync().ConfigureAwait(false); +#endif _cancellationRegistration = default; return true; } @@ -216,7 +228,11 @@ internal WorkWrapper(IWork work, int attemptsCount, CancellationToken i return false; _completion.TrySetException(ex); } - _cancellationRegistration.Dispose(); +#if NETSTANDARD2_0 + _cancellationRegistration.Dispose(); +#else + await _cancellationRegistration.DisposeAsync().ConfigureAwait(false); +#endif _cancellationRegistration = default; return true; } diff --git a/src/Shared/QueuedAccessFactory.cs b/src/Shared/QueuedAccessFactory.cs index a09a0d4..3a079e2 100644 --- a/src/Shared/QueuedAccessFactory.cs +++ b/src/Shared/QueuedAccessFactory.cs @@ -16,42 +16,42 @@ namespace AInq.Background.Tasks; internal static class QueuedAccessFactory { - public static IAsyncWork CreateQueuedAccess(IAccess access, int attemptsCount, int priority) + public static IAsyncWork CreateQueuedAccess(IAccess access, int priority, int attemptsCount) where TResource : notnull - => new QueuedAccess(access ?? throw new ArgumentNullException(nameof(access)), attemptsCount, priority); + => new QueuedAccess(access ?? throw new ArgumentNullException(nameof(access)), priority, attemptsCount); - public static IAsyncWork CreateQueuedAccess(IAccess access, int attemptsCount, int priority) + public static IAsyncWork CreateQueuedAccess(IAccess access, int priority, int attemptsCount) where TResource : notnull - => new QueuedAccess(access ?? throw new ArgumentNullException(nameof(access)), attemptsCount, priority); + => new QueuedAccess(access ?? throw new ArgumentNullException(nameof(access)), priority, attemptsCount); - public static IAsyncWork CreateQueuedAsyncAccess(IAsyncAccess asyncAccess, int attemptsCount, int priority) + public static IAsyncWork CreateQueuedAsyncAccess(IAsyncAccess asyncAccess, int priority, int attemptsCount) where TResource : notnull - => new QueuedAsyncAccess(asyncAccess ?? throw new ArgumentNullException(nameof(asyncAccess)), attemptsCount, priority); + => new QueuedAsyncAccess(asyncAccess ?? throw new ArgumentNullException(nameof(asyncAccess)), priority, attemptsCount); - public static IAsyncWork CreateQueuedAsyncAccess(IAsyncAccess asyncAccess, int attemptsCount, - int priority) + public static IAsyncWork CreateQueuedAsyncAccess(IAsyncAccess asyncAccess, int priority, + int attemptsCount) where TResource : notnull - => new QueuedAsyncAccess(asyncAccess ?? throw new ArgumentNullException(nameof(asyncAccess)), attemptsCount, priority); + => new QueuedAsyncAccess(asyncAccess ?? throw new ArgumentNullException(nameof(asyncAccess)), priority, attemptsCount); - public static IAsyncWork CreateQueuedInjectedAccess(int attemptsCount, int priority) + public static IAsyncWork CreateQueuedInjectedAccess(int priority, int attemptsCount) where TResource : notnull where TAccess : IAccess - => new QueuedInjectedAccess(attemptsCount, priority); + => new QueuedInjectedAccess(priority, attemptsCount); - public static IAsyncWork CreateQueuedInjectedAccess(int attemptsCount, int priority) + public static IAsyncWork CreateQueuedInjectedAccess(int priority, int attemptsCount) where TResource : notnull where TAccess : IAccess - => new QueuedInjectedAccess(attemptsCount, priority); + => new QueuedInjectedAccess(priority, attemptsCount); - public static IAsyncWork CreateQueuedInjectedAsyncAccess(int attemptsCount, int priority) + public static IAsyncWork CreateQueuedInjectedAsyncAccess(int priority, int attemptsCount) where TResource : notnull where TAsyncAccess : IAsyncAccess - => new QueuedInjectedAsyncAccess(attemptsCount, priority); + => new QueuedInjectedAsyncAccess(priority, attemptsCount); - public static IAsyncWork CreateQueuedInjectedAsyncAccess(int attemptsCount, int priority) + public static IAsyncWork CreateQueuedInjectedAsyncAccess(int priority, int attemptsCount) where TResource : notnull where TAsyncAccess : IAsyncAccess - => new QueuedInjectedAsyncAccess(attemptsCount, priority); + => new QueuedInjectedAsyncAccess(priority, attemptsCount); private class QueuedAccess : IAsyncWork where TResource : notnull @@ -60,7 +60,7 @@ private class QueuedAccess : IAsyncWork private readonly int _attemptsCount; private readonly int _priority; - public QueuedAccess(IAccess access, int attemptsCount, int priority) + public QueuedAccess(IAccess access, int priority, int attemptsCount) { _access = access ?? throw new ArgumentNullException(nameof(access)); _attemptsCount = attemptsCount; @@ -78,7 +78,7 @@ private class QueuedAccess : IAsyncWork private readonly int _attemptsCount; private readonly int _priority; - public QueuedAccess(IAccess access, int attemptsCount, int priority) + public QueuedAccess(IAccess access, int priority, int attemptsCount) { _access = access ?? throw new ArgumentNullException(nameof(access)); _attemptsCount = attemptsCount; @@ -96,7 +96,7 @@ private class QueuedAsyncAccess : IAsyncWork private readonly int _attemptsCount; private readonly int _priority; - public QueuedAsyncAccess(IAsyncAccess asyncAccess, int attemptsCount, int priority) + public QueuedAsyncAccess(IAsyncAccess asyncAccess, int priority, int attemptsCount) { _asyncAccess = asyncAccess ?? throw new ArgumentNullException(nameof(asyncAccess)); _attemptsCount = attemptsCount; @@ -114,7 +114,7 @@ private class QueuedAsyncAccess : IAsyncWork private readonly int _attemptsCount; private readonly int _priority; - public QueuedAsyncAccess(IAsyncAccess asyncAccess, int attemptsCount, int priority) + public QueuedAsyncAccess(IAsyncAccess asyncAccess, int priority, int attemptsCount) { _asyncAccess = asyncAccess ?? throw new ArgumentNullException(nameof(asyncAccess)); _attemptsCount = attemptsCount; @@ -132,7 +132,7 @@ private class QueuedInjectedAccess : IAsyncWork private readonly int _attemptsCount; private readonly int _priority; - public QueuedInjectedAccess(int attemptsCount, int priority) + public QueuedInjectedAccess(int priority, int attemptsCount) { _attemptsCount = attemptsCount; _priority = priority; @@ -149,7 +149,7 @@ private class QueuedInjectedAccess : IAsyncWork : IAsyncWork private readonly int _attemptsCount; private readonly int _priority; - public QueuedInjectedAsyncAccess(int attemptsCount, int priority) + public QueuedInjectedAsyncAccess(int priority, int attemptsCount) { _attemptsCount = attemptsCount; _priority = priority; @@ -183,7 +183,7 @@ private class QueuedInjectedAsyncAccess : IAsy private readonly int _attemptsCount; private readonly int _priority; - public QueuedInjectedAsyncAccess(int attemptsCount, int priority) + public QueuedInjectedAsyncAccess(int priority, int attemptsCount) { _attemptsCount = attemptsCount; _priority = priority; diff --git a/src/Shared/QueuedWorkFactory.cs b/src/Shared/QueuedWorkFactory.cs index 2284b41..a6401ca 100644 --- a/src/Shared/QueuedWorkFactory.cs +++ b/src/Shared/QueuedWorkFactory.cs @@ -16,34 +16,33 @@ namespace AInq.Background.Tasks; internal static class QueuedWorkFactory { - public static IAsyncWork CreateQueuedWork(IWork work, int attemptsCount, int priority) - => new QueuedWork(work ?? throw new ArgumentNullException(nameof(work)), attemptsCount, priority); + public static IAsyncWork CreateQueuedWork(IWork work, int priority, int attemptsCount) + => new QueuedWork(work ?? throw new ArgumentNullException(nameof(work)), priority, attemptsCount); - public static IAsyncWork CreateQueuedWork(IWork work, int attemptsCount, int priority) - => new QueuedWork(work ?? throw new ArgumentNullException(nameof(work)), attemptsCount, priority); + public static IAsyncWork CreateQueuedWork(IWork work, int priority, int attemptsCount) + => new QueuedWork(work ?? throw new ArgumentNullException(nameof(work)), priority, attemptsCount); - public static IAsyncWork CreateQueuedAsyncWork(IAsyncWork asyncWork, int attemptsCount, int priority) - => new QueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), attemptsCount, priority); + public static IAsyncWork CreateQueuedAsyncWork(IAsyncWork asyncWork, int priority, int attemptsCount) + => new QueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), priority, attemptsCount); - public static IAsyncWork CreateQueuedAsyncWork(IAsyncWork asyncWork, int attemptsCount, - int priority) - => new QueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), attemptsCount, priority); + public static IAsyncWork CreateQueuedAsyncWork(IAsyncWork asyncWork, int priority, int attemptsCount) + => new QueuedAsyncWork(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)), priority, attemptsCount); - public static IAsyncWork CreateQueuedInjectedWork(int attemptsCount, int priority) + public static IAsyncWork CreateQueuedInjectedWork(int priority, int attemptsCount) where TWork : IWork - => new QueuedInjectedWork(attemptsCount, priority); + => new QueuedInjectedWork(priority, attemptsCount); - public static IAsyncWork CreateQueuedInjectedWork(int attemptsCount, int priority) + public static IAsyncWork CreateQueuedInjectedWork(int priority, int attemptsCount) where TWork : IWork - => new QueuedInjectedWork(attemptsCount, priority); + => new QueuedInjectedWork(priority, attemptsCount); - public static IAsyncWork CreateQueuedInjectedAsyncWork(int attemptsCount, int priority) + public static IAsyncWork CreateQueuedInjectedAsyncWork(int priority, int attemptsCount) where TAsyncWork : IAsyncWork - => new QueuedInjectedAsyncWork(attemptsCount, priority); + => new QueuedInjectedAsyncWork(priority, attemptsCount); - public static IAsyncWork CreateQueuedInjectedAsyncWork(int attemptsCount, int priority) + public static IAsyncWork CreateQueuedInjectedAsyncWork(int priority, int attemptsCount) where TAsyncWork : IAsyncWork - => new QueuedInjectedAsyncWork(attemptsCount, priority); + => new QueuedInjectedAsyncWork(priority, attemptsCount); private class QueuedWork : IAsyncWork @@ -52,7 +51,7 @@ private class QueuedWork : IAsyncWork private readonly int _priority; private readonly IWork _work; - public QueuedWork(IWork work, int attemptsCount, int priority) + public QueuedWork(IWork work, int priority, int attemptsCount) { _work = work ?? throw new ArgumentNullException(nameof(work)); _attemptsCount = attemptsCount; @@ -70,7 +69,7 @@ private class QueuedWork : IAsyncWork private readonly int _priority; private readonly IWork _work; - public QueuedWork(IWork work, int attemptsCount, int priority) + public QueuedWork(IWork work, int priority, int attemptsCount) { _work = work ?? throw new ArgumentNullException(nameof(work)); _attemptsCount = attemptsCount; @@ -88,7 +87,7 @@ private class QueuedAsyncWork : IAsyncWork private readonly int _attemptsCount; private readonly int _priority; - public QueuedAsyncWork(IAsyncWork asyncWork, int attemptsCount, int priority) + public QueuedAsyncWork(IAsyncWork asyncWork, int priority, int attemptsCount) { _asyncWork = asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)); _attemptsCount = attemptsCount; @@ -106,7 +105,7 @@ private class QueuedAsyncWork : IAsyncWork private readonly int _attemptsCount; private readonly int _priority; - public QueuedAsyncWork(IAsyncWork asyncWork, int attemptsCount, int priority) + public QueuedAsyncWork(IAsyncWork asyncWork, int priority, int attemptsCount) { _asyncWork = asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)); _attemptsCount = attemptsCount; @@ -123,7 +122,7 @@ private class QueuedInjectedWork : IAsyncWork private readonly int _attemptsCount; private readonly int _priority; - public QueuedInjectedWork(int attemptsCount, int priority) + public QueuedInjectedWork(int priority, int attemptsCount) { _attemptsCount = attemptsCount; _priority = priority; @@ -139,7 +138,7 @@ private class QueuedInjectedWork : IAsyncWork private readonly int _attemptsCount; private readonly int _priority; - public QueuedInjectedWork(int attemptsCount, int priority) + public QueuedInjectedWork(int priority, int attemptsCount) { _attemptsCount = attemptsCount; _priority = priority; @@ -155,7 +154,7 @@ private class QueuedInjectedAsyncWork : IAsyncWork private readonly int _attemptsCount; private readonly int _priority; - public QueuedInjectedAsyncWork(int attemptsCount, int priority) + public QueuedInjectedAsyncWork(int priority, int attemptsCount) { _attemptsCount = attemptsCount; _priority = priority; @@ -171,7 +170,7 @@ private class QueuedInjectedAsyncWork : IAsyncWork private readonly int _attemptsCount; private readonly int _priority; - public QueuedInjectedAsyncWork(int attemptsCount, int priority) + public QueuedInjectedAsyncWork(int priority, int attemptsCount) { _attemptsCount = attemptsCount; _priority = priority;