@@ -13,7 +13,7 @@ public sealed class StockGrain : Grain, IStockGrain
1313 public override async Task OnActivateAsync ( CancellationToken cancellationToken )
1414 {
1515 var stock = this . GetPrimaryKeyString ( ) ;
16- await UpdatePrice ( stock ) ;
16+ await UpdatePrice ( stock , cancellationToken ) ;
1717
1818 this . RegisterGrainTimer (
1919 UpdatePrice ,
@@ -28,21 +28,19 @@ public override async Task OnActivateAsync(CancellationToken cancellationToken)
2828 await base . OnActivateAsync ( cancellationToken ) ;
2929 }
3030
31- private async Task UpdatePrice ( string stock )
31+ private async Task UpdatePrice ( string stock , CancellationToken cancellationToken )
3232 {
33- var priceTask = GetPriceQuote ( stock ) ;
34-
35- // read the results
36- _price = await priceTask ;
33+ _price = await GetPriceQuote ( stock , cancellationToken ) ;
3734 }
3835
39- private async Task < string > GetPriceQuote ( string stock )
36+ private async Task < string > GetPriceQuote ( string stock , CancellationToken cancellationToken )
4037 {
4138 using var resp =
4239 await _httpClient . GetAsync (
43- $ "https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol={ stock } &apikey={ ApiKey } &datatype=csv") ;
40+ $ "https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol={ stock } &apikey={ ApiKey } &datatype=csv",
41+ cancellationToken ) ;
4442
45- return await resp . Content . ReadAsStringAsync ( ) ;
43+ return await resp . Content . ReadAsStringAsync ( cancellationToken ) ;
4644 }
4745
4846 public Task < string > GetPrice ( ) => Task . FromResult ( _price ) ;
0 commit comments