From a00f5f6e9e3ee2bc8009d8f0b5180abf014dc423 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Wed, 30 Sep 2020 19:48:35 +0200 Subject: [PATCH] Added cancellation token --- FastRng/Double/ShapeFitter.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/FastRng/Double/ShapeFitter.cs b/FastRng/Double/ShapeFitter.cs index 5f53e14..e786ad1 100644 --- a/FastRng/Double/ShapeFitter.cs +++ b/FastRng/Double/ShapeFitter.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.CompilerServices; +using System.Threading; using System.Threading.Tasks; namespace FastRng.Double @@ -29,11 +30,11 @@ namespace FastRng.Double } } - public async ValueTask NextNumber() + public async ValueTask NextNumber(CancellationToken token = default) { - while (true) + while (!token.IsCancellationRequested) { - var nextNumber = await this.rng.GetUniform(); + var nextNumber = await this.rng.GetUniform(token); var nextBucket = (int)Math.Floor(nextNumber * this.sampleSize); this.samples[nextBucket] += this.probabilities[nextBucket]; @@ -43,6 +44,8 @@ namespace FastRng.Double return nextNumber; } } + + return double.NaN; } } } \ No newline at end of file