STREAMS - Replay
There are occasions where you need to make a large or long duration network call, what if you could return the previous results
while the current network call is in progress? What if you don’t have a network connection and the method should just “wait” until it does?
The Replay
middleware is designed to help you with this.
Setup
So here we have a standard HTTP call on our streaming async enumerable protocol. Nothing special here, but once we turn on the Replay
middleware, we can return the previous results while the current network call is in progress.
In Your Code
At first, you’ll see there is nothing special, but the cool part here is that the async enumerable will “pump” twice. The first time for the previous results (if the call has previous been made) and the second time with the new response from your long call.
Configuration
Much like other middleware, you can use the Microsoft.Extensions.Configuration.