Last active
April 6, 2017 00:45
-
-
Save Maarten88/dc6f0392ec9a50e12a754d8b6540d6a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task StartCounterTimer() | |
{ | |
if (this.timer != null) | |
throw new Exception("Can't start: already started"); | |
await this.Dispatch(new StartCounterAction()); | |
await this.WriteStateAsync(); | |
this.timer = this.RegisterTimer(async (state) => { | |
var action = new IncrementCounterAction(); | |
// This sends the action to the clients for processing there | |
// This processes the action here on the server, and also sends the syncstate to make sure the outcome is the same | |
// The order of events is important here | |
await this.Dispatch(action); | |
await this.WriteStateAsync(); | |
await this.actionsToClientStream.OnNextAsync(action); | |
}, null, TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(3)); | |
await this.actionsToClientStream.OnNextAsync(new CounterStartedAction()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment