public PeriodicReporter(ISender sender, FlushOptions flushOptions) { this.sender = sender; batch = new Buffer <Span>(flushOptions.MaxBufferSize); periodicAsync = new PeriodicAsync(FlushAsync, flushOptions.FlushInterval, flushOptions.CancellationToken); periodicAsync.Start(this); }
public async Task LoopInvokesActionWithSuppliedArg() { var tcs = new TaskCompletionSource <object>(); var cts = new CancellationTokenSource(); var loop = new PeriodicAsync((obj, ct) => { if (obj is TaskCompletionSource <object> t) { t.TrySetResult(null); cts.Cancel(); } return(Task.CompletedTask); }, TimeSpan.FromMilliseconds(100), cts.Token); loop.Start(tcs); await tcs.Task; }