mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-03-05 13:20:20 -05:00
Fixed: A season pack import taking a long time should no longer cause the download to be deleted prematurely.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace NzbDrone.Common.TPL
|
||||
{
|
||||
@@ -7,6 +8,9 @@ namespace NzbDrone.Common.TPL
|
||||
private readonly Action _action;
|
||||
private readonly System.Timers.Timer _timer;
|
||||
|
||||
private volatile int _paused;
|
||||
private volatile bool _triggered;
|
||||
|
||||
public Debouncer(Action action, TimeSpan debounceDuration)
|
||||
{
|
||||
_action = action;
|
||||
@@ -16,13 +20,45 @@ namespace NzbDrone.Common.TPL
|
||||
|
||||
void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
_timer.Stop();
|
||||
_action();
|
||||
if (_paused == 0)
|
||||
{
|
||||
_triggered = false;
|
||||
_timer.Stop();
|
||||
_action();
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
_timer.Start();
|
||||
lock (_timer)
|
||||
{
|
||||
_triggered = true;
|
||||
if (_paused == 0)
|
||||
{
|
||||
_timer.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
lock (_timer)
|
||||
{
|
||||
_paused++;
|
||||
_timer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
public void Resume()
|
||||
{
|
||||
lock (_timer)
|
||||
{
|
||||
_paused--;
|
||||
if (_paused == 0 && _triggered)
|
||||
{
|
||||
_timer.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user