IVSoftware.Portable.EpochCompletionSource 1.0.0-beta

Prefix Reserved
This is a prerelease version of IVSoftware.Portable.EpochCompletionSource.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package IVSoftware.Portable.EpochCompletionSource --version 1.0.0-beta
                    
NuGet\Install-Package IVSoftware.Portable.EpochCompletionSource -Version 1.0.0-beta
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="IVSoftware.Portable.EpochCompletionSource" Version="1.0.0-beta" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="IVSoftware.Portable.EpochCompletionSource" Version="1.0.0-beta" />
                    
Directory.Packages.props
<PackageReference Include="IVSoftware.Portable.EpochCompletionSource" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add IVSoftware.Portable.EpochCompletionSource --version 1.0.0-beta
                    
#r "nuget: IVSoftware.Portable.EpochCompletionSource, 1.0.0-beta"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package IVSoftware.Portable.EpochCompletionSource@1.0.0-beta
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=IVSoftware.Portable.EpochCompletionSource&version=1.0.0-beta&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=IVSoftware.Portable.EpochCompletionSource&version=1.0.0-beta&prerelease
                    
Install as a Cake Tool

IVSoftware.Portable.EpochCompletionSource [GitHub]

A reusable abstraction for awaiting renewable "epochs" that complete deterministically by scope or probabilistically by quiescent time.

Offers a Hybrid Solution

IVSoftware.Portable.WatchdogTimer allows a class to restart settling intervals without task cancellation exceptions, extending activity until a dwell interval completes.

IVSoftware.Portable.Disposable.DisposableHost provides a concurrent, reference-counted scope that defines a shared, ephemeral context for the duration of an epoch.

The missing piece is how an external observer can deterministically await an object that employs either mechanism without guessing timing. One compelling reason to do this would be to compose a unit test that observes it.

Example - Filter a Collection after Input Text Settles

Consider a class that models an IME.

class SettleBeforeFilterModel : INotifyPropertyChanged
{
    public SettleBeforeFilterModel()
    {
        WDTSettle = new WatchdogTimer(defaultCompleteAction: FilterList)
        {
            Interval = TimeSpan.FromSeconds(0.1)
        };
    }

    /// <summary>
    /// Placeholder - Will apply filtering to Items based on settled input text.
    /// </summary>
    private void FilterList() { } 

    public string InputText
    {
        get => _inputText;
        set
        {
            if (!Equals(_inputText, value))
            {
                _inputText = value;
                WDTSettle.StartOrRestart();
                OnPropertyChanged();
            }
        }
    }
    string _inputText = string.Empty;

	public ObservableCollection<Item>{ get; } = new();    

    public WatchdogTimer WDTSettle { get; }
    
    protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) =>
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

    public event PropertyChangedEventHandler? PropertyChanged;
}

This works at runtime, but it is not testable. There is no deterministic way to know when the final filter operation has completed (i.e., via CollectionChanged on Items). Polling or inserting a "magic delay" is brittle and race-prone.

Converting to an Awaitable Class

By composing an EpochController, the model becomes awaitable without changing its public behavior:

class SettleBeforeFilterModel : INotifyPropertyChanged, IAwaitableEpoch
{
    readonly EpochController _epoch = new();

    public string InputText
    {
        get => _inputText;
        set
        {
            if (!Equals(_inputText, value))
            {
                _inputText = value;
                WDTEpoch.StartOrRestart();
                OnPropertyChanged();
            }
        }
    }
    string _inputText = string.Empty;

    public DisposableHost DHostEpoch => _epoch.DHostEpoch;
    public WatchdogTimer WDTEpoch => _epoch.WDTEpoch;
    public TaskAwaiter GetAwaiter() => _epoch.GetAwaiter();
}

Internally, EpochController binds quiescent activity and deterministic scopes into a single renewable completion boundary. Each epoch completes only when all concerns have finished.

Deterministic Testing

The unit test can now await behavior directly:

sbf.InputText = "abc";
await sbf; // waits for dwell to settle

using (sbf.DHostEpoch.GetToken())
{
    sbf.InputText = "def";
    // epoch remains open until scope exits
}

await sbf; // completes after both concerns finish

The await completes at:

max(quiescence completion, deterministic scope completion)

Summary

EpochCompletionSource turns time-based settling and scope-based lifetimes into a single awaitable concept. The result is code that behaves the same at runtime, but becomes precise, deterministic, and testable without ceremony.

This means that any external client, for test purposes or any other reason, can await an instance of this class and act with confidence on its temporal state without having to resort to polling, sleeps, or timing assumptions.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated

Initial beta release.

- Introduces IAwaitableEpoch as a compositional abstraction over
    DisposableHost and WatchdogTimer.
- Enables deterministic awaiting of quiescent or scoped activity.
- Designed primarily for UI stabilization and testability scenarios.