-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDataRefresherStatusService.cs
More file actions
49 lines (41 loc) · 1.22 KB
/
DataRefresherStatusService.cs
File metadata and controls
49 lines (41 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Threading;
using System.Threading.Tasks;
namespace BookingSystem.AspNetCore.Services
{
public class DataRefresherStatusService
{
private readonly SemaphoreSlim _completionSemaphore = new SemaphoreSlim(0, 1);
private bool _isRefresherConfigured = false;
private bool _hasCompletedCycle = false;
public void SetRefresherConfigured(bool isConfigured)
{
_isRefresherConfigured = isConfigured;
}
public bool IsRefresherConfigured()
{
return _isRefresherConfigured;
}
public void SignalCycleCompletion()
{
_hasCompletedCycle = true;
// Release the semaphore if someone is waiting on it
if (_completionSemaphore.CurrentCount == 0)
{
_completionSemaphore.Release();
}
}
public bool HasCompletedCycle()
{
return _hasCompletedCycle;
}
public async Task WaitForCycleCompletion(TimeSpan timeout)
{
if (_hasCompletedCycle)
{
return;
}
await _completionSemaphore.WaitAsync(timeout);
}
}
}