public override async Task OnActivateAsync() { // derive the source grains to aggregate from the grain key var parts = GrainKey.Split('|'); _leftGrain = GrainFactory.GetGrain <IProducerGrain>(parts[0]); _rightGrain = GrainFactory.GetGrain <IProducerGrain>(parts[1]); // get the starting values as they are now before starting to long poll _leftValue = await _leftGrain.GetAsync(); _rightValue = await _rightGrain.GetAsync(); await FulfillAsync(); // start long polling the left grain _leftPoll = await RegisterReactivePollAsync( null, // dont initialize for this one () => _leftGrain.LongPollAsync(_leftValue.Version), result => result.IsValid, apply => { _leftValue = apply; _logger.LogInformation( "{@Time}: {@GrainType} {@GrainKey} updated left value to {@Value} with version {@Version}", DateTime.Now.TimeOfDay, GrainType, GrainKey, _leftValue.Value, _leftValue.Version); return(FulfillAsync()); }, failed => { _logger.LogWarning("The reactive poll timed out by returning a 'none' response before Orleans could break the promise."); return(Task.CompletedTask); }); // start long polling the right grain _rightPoll = await RegisterReactivePollAsync( null, // dont initialize for this one () => _rightGrain.LongPollAsync(_rightValue.Version), result => result.IsValid, apply => { _rightValue = apply; _logger.LogInformation( "{@Time}: {@GrainType} {@GrainKey} updated right value to {@Value} with version {@Version}", DateTime.Now.TimeOfDay, GrainType, GrainKey, _rightValue.Value, _rightValue.Version); return(FulfillAsync()); }, failed => { _logger.LogWarning("The reactive poll timed out by returning a 'none' response before Orleans could break the promise."); return(Task.CompletedTask); }); await base.OnActivateAsync(); }
public override async Task OnActivateAsync() { // derive the source grains to aggregate from the grain key var parts = GrainKey.Split('|'); _leftGrain = GrainFactory.GetGrain <IProducerGrain>(parts[0]); _rightGrain = GrainFactory.GetGrain <IProducerGrain>(parts[1]); // get the starting values as they are now _leftValue = await _leftGrain.GetAsync(); _rightValue = await _rightGrain.GetAsync(); await FulfillAsync(); // start long polling _leftPollTimer = RegisterTimer(_ => LongPollLeftAsync(), null, TimeSpan.Zero, TimeSpan.FromMilliseconds(1)); _rightPollTimer = RegisterTimer(_ => LongPollRightAsync(), null, TimeSpan.Zero, TimeSpan.FromMilliseconds(1)); await base.OnActivateAsync(); }