Skip to content

Commit

Permalink
add xml doc to PauseTokenSource.cs file
Browse files Browse the repository at this point in the history
  • Loading branch information
bezzad committed Sep 18, 2024
1 parent a05627e commit c991bf1
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/Downloader/PauseTokenSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,35 @@

namespace Downloader;

/// <summary>
/// Represents a source for creating and managing pause tokens.
/// </summary>
public class PauseTokenSource
{
private volatile TaskCompletionSource<bool> _tcsPaused;

/// <summary>
/// Gets the pause token associated with this source.
/// </summary>
public PauseToken Token => new PauseToken(this);

/// <summary>
/// Gets a value indicating whether the operation is paused.
/// </summary>
public bool IsPaused => _tcsPaused != null;

/// <summary>
/// Pauses the operation by creating a new task completion source.
/// </summary>
public void Pause()
{
// if (tcsPause == null) tcsPause = new TaskCompletionSource<bool>();
Interlocked.CompareExchange(ref _tcsPaused, new TaskCompletionSource<bool>(), null);
}

/// <summary>
/// Resumes the operation by setting the result of the task completion source and resetting it.
/// </summary>
public void Resume()
{
// we need to do this in a standard compare-exchange loop:
Expand All @@ -38,8 +54,12 @@ public void Resume()
}
}

/// <summary>
/// Waits asynchronously while the operation is paused.
/// </summary>
/// <returns>A task that represents the asynchronous wait operation.</returns>
internal Task WaitWhilePausedAsync()
{
return _tcsPaused?.Task ?? Task.FromResult(true);
}
}
}

0 comments on commit c991bf1

Please sign in to comment.