Skip to content

Commit

Permalink
Disposing cancellation tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
rithik-b committed Mar 17, 2022
1 parent 4135952 commit 810d84c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions MorePlaylists/UI/ViewControllers/IListViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace MorePlaylists.UI;
public interface IListViewController
{
ViewController ViewController { get; }
event Action<IEntry> DidSelectPlaylist;
event Action DidClickSource;
event Action<IEntry>? DidSelectPlaylist;
event Action? DidClickSource;
void ShowPlaylistsForSource(ISource source);
void SetEntryAsOwned(IEntry entry);
void AbortLoading();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ protected override void DidActivate(bool firstActivation, bool addedToHierarchy,
sourceButton.image.sprite = currentSource.Logo;
inputFieldView.ClearInput();
loadCancellationTokenSource?.Cancel();
loadCancellationTokenSource?.Dispose();
loadCancellationTokenSource = new CancellationTokenSource();
_ = LoadPlaylists(currentSource, loadCancellationTokenSource.Token);
}
Expand Down Expand Up @@ -89,6 +90,7 @@ private void PostParse()
inputFieldView.onValueChanged.AddListener(inputFieldView =>
{
searchCancellationTokenSource?.Cancel();
searchCancellationTokenSource?.Dispose();
searchCancellationTokenSource = new CancellationTokenSource();
_ = SearchAsync(searchCancellationTokenSource.Token);
});
Expand All @@ -103,6 +105,9 @@ private void PostParse()
public void AbortLoading()
{
loadCancellationTokenSource?.Cancel();
loadCancellationTokenSource?.Dispose();
searchCancellationTokenSource?.Cancel();
searchCancellationTokenSource?.Dispose();
Loaded = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void SetCurrentPlaylist(IEntry entry)
}

cancellationTokenSource?.Cancel();
cancellationTokenSource?.Dispose();
cancellationTokenSource = new CancellationTokenSource();

_ = InitSongList(entry, cancellationTokenSource.Token);
Expand Down

0 comments on commit 810d84c

Please sign in to comment.