|
|
|
@ -23,6 +23,8 @@ namespace NzbDrone.Core.Messaging.Commands
|
|
|
|
|
lock (_mutex)
|
|
|
|
|
{
|
|
|
|
|
_items.Add(item);
|
|
|
|
|
|
|
|
|
|
Monitor.PulseAll(_mutex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -68,6 +70,8 @@ namespace NzbDrone.Core.Messaging.Commands
|
|
|
|
|
{
|
|
|
|
|
_items.Remove(command);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Monitor.PulseAll(_mutex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -83,6 +87,8 @@ namespace NzbDrone.Core.Messaging.Commands
|
|
|
|
|
{
|
|
|
|
|
_items.Remove(command);
|
|
|
|
|
rval = true;
|
|
|
|
|
|
|
|
|
|
Monitor.PulseAll(_mutex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -102,14 +108,39 @@ namespace NzbDrone.Core.Messaging.Commands
|
|
|
|
|
|
|
|
|
|
public IEnumerable<CommandModel> GetConsumingEnumerable(CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
cancellationToken.Register(PulseAllConsumers);
|
|
|
|
|
|
|
|
|
|
while (!cancellationToken.IsCancellationRequested)
|
|
|
|
|
{
|
|
|
|
|
if (TryGet(out var command))
|
|
|
|
|
CommandModel command = null;
|
|
|
|
|
|
|
|
|
|
lock (_mutex)
|
|
|
|
|
{
|
|
|
|
|
if (cancellationToken.IsCancellationRequested)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!TryGet(out command))
|
|
|
|
|
{
|
|
|
|
|
Monitor.Wait(_mutex);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (command != null)
|
|
|
|
|
{
|
|
|
|
|
yield return command;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Thread.Sleep(10);
|
|
|
|
|
public void PulseAllConsumers()
|
|
|
|
|
{
|
|
|
|
|
// Signal all consumers to reevaluate cancellation token
|
|
|
|
|
lock (_mutex)
|
|
|
|
|
{
|
|
|
|
|
Monitor.PulseAll(_mutex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|