Skip to content

STREAMS - Refresh Timer

There are scenarios where you want to have data requests be called every so often. The RefreshTimer middleware is designed to help you with this.

Attribute Setup

[RefreshTimer(3000)] // every 3 seconds
public class MyStreamRequestHandler : IStreamRequestHandler<MyRequest, string>
{
public async IAsyncEnumerable<string> Handle(MyRequest request, [EnumeratorCancellation] CancellationToken cancellationToken)
{
yield return DateTimeOffset.Now.ToString("h:mm:ss tt");
}
}

Configuration

Much like other middleware, you can use the Microsoft.Extensions.Configuration.

{
"Mediator": {
"TimerRefresh": {
"MyNamespace.MyStreamHandler": {
"IntervalSeconds": 20
}
}
}
}