mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.5 KiB
55 lines
1.5 KiB
namespace ErsatzTV.Core; |
|
|
|
public class SystemStartup : IDisposable |
|
{ |
|
private readonly SemaphoreSlim _databaseStartup = new(0, 100); |
|
private readonly SemaphoreSlim _searchIndexStartup = new(0, 100); |
|
|
|
private bool _disposedValue; |
|
|
|
public bool IsDatabaseReady { get; private set; } |
|
public bool IsSearchIndexReady { get; private set; } |
|
|
|
public void Dispose() |
|
{ |
|
Dispose(true); |
|
GC.SuppressFinalize(this); |
|
} |
|
|
|
public event EventHandler OnDatabaseReady; |
|
public event EventHandler OnSearchIndexReady; |
|
|
|
public async Task WaitForDatabase(CancellationToken cancellationToken) => |
|
await _databaseStartup.WaitAsync(cancellationToken); |
|
|
|
public async Task WaitForSearchIndex(CancellationToken cancellationToken) => |
|
await _searchIndexStartup.WaitAsync(cancellationToken); |
|
|
|
public void DatabaseIsReady() |
|
{ |
|
_databaseStartup.Release(100); |
|
IsDatabaseReady = true; |
|
OnDatabaseReady?.Invoke(this, EventArgs.Empty); |
|
} |
|
|
|
public void SearchIndexIsReady() |
|
{ |
|
_searchIndexStartup.Release(100); |
|
IsSearchIndexReady = true; |
|
OnSearchIndexReady?.Invoke(this, EventArgs.Empty); |
|
} |
|
|
|
protected virtual void Dispose(bool disposing) |
|
{ |
|
if (!_disposedValue) |
|
{ |
|
if (disposing) |
|
{ |
|
_databaseStartup.Dispose(); |
|
_searchIndexStartup.Dispose(); |
|
} |
|
|
|
_disposedValue = true; |
|
} |
|
} |
|
}
|
|
|