Skip to content

Commit

Permalink
convert PauseToken to record type and add xml docs
Browse files Browse the repository at this point in the history
  • Loading branch information
bezzad committed Sep 18, 2024
1 parent 51b9239 commit a05627e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
17 changes: 4 additions & 13 deletions src/Downloader/Packet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@

namespace Downloader;

internal class Packet : IDisposable, ISizeableObject
internal class Packet(long position, byte[] data, int len) : IDisposable, ISizeableObject
{
public volatile bool IsDisposed = false;
public byte[] Data { get; set; }
public int Length { get; set; }
public long Position { get; set; }
public byte[] Data { get; set; } = data;
public int Length { get; set; } = len;
public long Position { get; set; } = position;
public long EndOffset => Position + Length;

public Packet(long position, byte[] data, int len)
{
Position = position;
Data = data;
Length = len;
}

public void Dispose()
{
IsDisposed = true;
Data = null;
Position = 0;
}
Expand Down
19 changes: 17 additions & 2 deletions src/Downloader/PauseToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,35 @@

namespace Downloader;

public struct PauseToken
/// <summary>
/// Represents a pause token that can be used to pause and resume operations.
/// </summary>
public record PauseToken
{
private readonly PauseTokenSource _tokenSource;

/// <summary>
/// Gets a value indicating whether the operation is paused.
/// </summary>
public bool IsPaused => _tokenSource?.IsPaused == true;

/// <summary>
/// Initializes a new instance of the <see cref="PauseToken"/> class.
/// </summary>
/// <param name="source">The pause token source.</param>
internal PauseToken(PauseTokenSource source)
{
_tokenSource = source;
}

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

0 comments on commit a05627e

Please sign in to comment.