Fix copy overwrites the source files sometimes

This commit is contained in:
2023-07-03 10:05:41 +02:00
parent 4f9e69f2ab
commit c29df77d39
7 changed files with 49 additions and 44 deletions

View File

@@ -27,19 +27,42 @@ public record Container(
ReadOnlyExtensionCollection Extensions,
IObservable<IChangeSet<AbsolutePath, string>> Items) : IContainer
{
private readonly Lazy<ReadOnlyObservableCollection<AbsolutePath>> _itemsCollectionLazy =
new (() =>
new(() =>
{
Items.Bind(out var items).Subscribe();
return items;
});
private readonly CancellationTokenSource _loadingCancellationTokenSource = new();
private readonly BehaviorSubject<bool> _isLoading = new(false);
public CancellationToken LoadingCancellationToken => _loadingCancellationTokenSource.Token;
public BehaviorSubject<bool> IsLoading { get; } = new(false);
IObservable<bool> IContainer.IsLoading => IsLoading.AsObservable();
public IObservable<bool> IsLoading => _isLoading.AsObservable();
public bool? IsLoaded { get; private set; }
public AbsolutePathType Type => AbsolutePathType.Container;
public ReadOnlyObservableCollection<AbsolutePath> ItemsCollection => _itemsCollectionLazy.Value;
public void CancelLoading() => _loadingCancellationTokenSource.Cancel();
public async Task WaitForLoaded(CancellationToken token = default)
{
while (IsLoaded != true) await Task.Delay(1, token);
}
public void StartLoading()
{
_isLoading.OnNext(true);
IsLoaded = false;
}
public void StopLoading()
{
_isLoading.OnNext(false);
IsLoaded = true;
}
public void CancelLoading()
{
_loadingCancellationTokenSource.Cancel();
_isLoading.OnNext(false);
IsLoaded = true;
}
}