Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/NATS.Client.Core/Commands/PingCommand.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics;
using System.Threading.Tasks.Sources;
using NATS.Client.Core.Internal;

Expand All @@ -6,7 +7,7 @@ namespace NATS.Client.Core.Commands;
internal class PingCommand : IValueTaskSource<TimeSpan>, IObjectPoolNode<PingCommand>
{
private readonly ObjectPool? _pool;
private DateTimeOffset _start;
private Stopwatch _stopwatch;
private ManualResetValueTaskSourceCore<TimeSpan> _core;
private PingCommand? _next;

Expand All @@ -17,20 +18,20 @@ public PingCommand(ObjectPool? pool)
{
RunContinuationsAsynchronously = true,
};
_start = DateTimeOffset.MinValue;
_stopwatch = new Stopwatch();
}

public ref PingCommand? NextNode => ref _next;

public void Start() => _start = DateTimeOffset.UtcNow;
public void Start() => _stopwatch.Restart();

public void SetResult() => _core.SetResult(DateTimeOffset.UtcNow - _start);
public void SetResult() => _core.SetResult(_stopwatch.Elapsed);

public void SetCanceled() => _core.SetException(new OperationCanceledException());

public void Reset()
{
_start = DateTimeOffset.MinValue;
_stopwatch.Reset();
_core.Reset();
}

Expand Down