Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save irfanbaysal/07dede37a83ad28691f608660b82b2d5 to your computer and use it in GitHub Desktop.
Save irfanbaysal/07dede37a83ad28691f608660b82b2d5 to your computer and use it in GitHub Desktop.
CancellationToken Subscription & Unsubscription in UniTask
public void StartAsyncOps(ref CancellationTokenSource cancellationTokenSource)
{
if (cancellationTokenSource != null)
{
cancellationTokenSource.Dispose();
}
cancellationTokenSource = new CancellationTokenSource();
}
public void StopAsyncOps(CancellationTokenSource cancellationTokenSource)
{
if (cancellationTokenSource == null) return;
if (cancellationTokenSource.IsCancellationRequested) return;
cancellationTokenSource.Cancel();
cancellationTokenSource.Dispose();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment