Aesthetic question really.
Given this code (polling unavoidable):
protected override async Task ExecuteAsync(CancellationToken ct) { // move the loop here somehow? await Task.WhenAll( Task.Run(async () => await this.PollA(ct), ct), Task.Run(async () => await this.PollB(ct), ct), Task.Run(async () => await this.PollC(ct), ct)) .ConfigureAwait(false); } the polling methods look like this at the moment, each one has a different delay.
private async Task Poll(CancellationToken ct) { while (!ct.IsCancellationRequested) { await Task.Delay(Math.Max(1000, CONFIGA), ct); this._logger.StartAction("poll A status"); this._logger.StopAction("poll A status"); } } Is there a way to structure a continuation that removes the loop in each of the Poll methods
private async Task Poll(CancellationToken ct) { await Task.Delay(Math.Max(1000, CONFIGA), ct); this._logger.StartAction("poll A status"); this._logger.StopAction("poll A status"); } This might not even be the right pattern, but it seems better than having three infinite loops.
Task.WhenAny([A,B,C]) => // recreate any complete task as soon as it returns // and await the new "continuation"?
await Task.WhenAll(this.PollA(ct), this.PollB(ct), this.PollC(ct))? But certainly you could just dowhile(!ct.IsCancellationRequested)) await Task.WhenAny(this.PollA(ct), this.PollB(ct), this.PollC(ct))if that was the behaviour you wanted.