add cancellable time span await

This commit is contained in:
Youmu Liu
2025-11-21 18:11:52 +08:00
parent 98f47aaa53
commit 61fbce14a2
3 changed files with 63 additions and 23 deletions
@@ -41,6 +41,9 @@ namespace StgSharp.Timing
private bool _subscribed;
private int _emittedSpanCount; // legacy counter
// internal ended flag (0 = running, 1 = ended)
private int _endedFlag = 0;
private readonly TimeSequence _sequence;
private readonly TimeSourceProviderBase _timeSource;
@@ -62,6 +65,11 @@ namespace StgSharp.Timing
_pendingSpans = 0;
}
/// <summary>
/// True when the provider has reached its end and will not emit further spans.
/// </summary>
public bool IsEnded => Volatile.Read(ref _endedFlag) != 0;
public double CurrentSecond
{
get => (double)_sequence.PreviousFrameTick / _timeSource.Frequency;