I have a Controller Action like this:
[HttpPost("Post")]
public async Task Post([FromBody] UpdateDataCommand command)
{
await _mediator.Send(command);
}
It is done in .Net Core, and is using MediatR to process commands.
Now, the UpdateDataCommand has a integer StationId property that identifies the Station number. When a client application calls this method by doing a Post, it updates data in the database. What I want to do using Rx .Net is to somehow start a timer after the Await _mediator.Send(command). The timer will be set to 1 minute. After 1 minute, I want to call another method that will set the flag in the database but only for this StationId. If someone does a Post using the same StationId, the timer should reset itself.
In pseudo-code looks like this:
[HttpPost("Post")]
public async Task Post([FromBody] UpdateDataCommand command)
{
int stationId = command.StationId;
// let's assume stationId==2
//saves data for stationId==2
await _mediator.Send(command);
//Start a timer of 1 min
//if timer fires (meaning the 1 minute has passed) call Method2();
//if client does another "Post" for stationId==2 in the meantime
(let's say that the client does another "Post" for stationId==2 after 20 sec)
then reset the timer
}
How to do this using Reactive Extensions in.Net?
UPDATE (@Enigmativity):
It still doesn't work,I put the timer to 10sec and if you look at the output times you'll see that I have made a Post on 09:17:49 (which started a timer of 10 sec), then I made a new Post at 09:17:55 (which has started another timer, but it should only have reset the old one) and bothe the timers kicked off, one 10 secs after the first call, and another 10 sec after the second call.: