public async Task OnRunAsync(CancellationTokenSource cancellationTokenSource) { var rbw = EnumerativeBackgroundWorker.Make ( inputs: SorterGenomeEvalGridVmInitial.SorterGenomeEvalVms .Select( ev => new Tuple <ISorterGenomeEval, ISorterMutateParams> ( ev.SorterGenomeEval, SorterMutateParamsVm.GetParams )), mapper: (s, c) => { return(IterationResult.Make ( data: s.Item1.ToSgMutantProfile(s.Item2), progressStatus: ProgressStatus.StepComplete )); } ); Busy = true; //_cancellationTokenSource = cancellationTokenSource; rbw.OnIterationResult.Subscribe(UpdateSorterMutateResults); await rbw.Start(cancellationTokenSource); Busy = false; }
public void TestCancel() { var tokenSource = new CancellationTokenSource(); var inputs = new[] { 42, 43, 44, 45 }; var ibw = EnumerativeBackgroundWorker.Make ( inputs, (i, c) => IterationResult.Make(i + 1, ProgressStatus.StepComplete) ); var nextResult = 0; ibw.OnIterationResult.Subscribe( r => { nextResult = r.Data; tokenSource.Cancel(); }); ibw.Start(tokenSource); Thread.Sleep(100); Assert.IsTrue(ibw.CurrentOutput < 46); Assert.IsTrue(ibw.CurrentIteration < inputs.Length); Assert.AreEqual(ibw.CurrentOutput, nextResult); }
public void TestCtor() { var inputs = new[] { 42, 43, 44, 45 }; var ibw = EnumerativeBackgroundWorker.Make ( inputs, (i, c) => IterationResult.Make(i + 1, ProgressStatus.StepComplete) ); Assert.AreEqual(ibw.CurrentInput, inputs[0]); Assert.AreEqual(ibw.CurrentIteration, 0); Assert.AreEqual(ibw.TotalIterations, inputs.Count()); }
async Task GenerateSamples() { Busy = true; var samplerParams = GetSorterSamplerParams(KeyCount.Value); _stopwatch.Reset(); _stopwatch.Start(); _cancellationTokenSource = new CancellationTokenSource(); var rando = Rando.Fast(Seed.Value); var inputs = Enumerable.Range(0, 10000).Select(t => rando.NextInt()); IEnumerativeBackgroundWorker <int, SorterSamplerResults> ibw = EnumerativeBackgroundWorker.Make ( inputs: inputs, mapper: (i, c) => { var sorterSamplerResults = SorterRandomSampler.SorterSampler( keyCount: KeyCount.Value, switchCount: samplerParams.SwitchCount, histogramMin: samplerParams.HistogramMin, histogramMax: samplerParams.HistogramMax, seed: i, repCount: ReportFrequency.Value, lowRangeMax: LowRangeMax.Value, highRangeMin: HighRangeMin.Value, cancellationToken: _cancellationTokenSource.Token ); if (sorterSamplerResults.WasCancelled) { return(IterationResult.Make(default(SorterSamplerResults), ProgressStatus.StepIncomplete)); } return(IterationResult.Make(sorterSamplerResults, ProgressStatus.StepComplete)); } ); ibw.OnIterationResult.Subscribe(UpdateSorterSamplerResults); await ibw.Start(_cancellationTokenSource); Busy = false; _stopwatch.Stop(); CommandManager.InvalidateRequerySuggested(); }
public void TestUpdate() { var tokenSource = new CancellationTokenSource(); var inputs = new[] { 42, 43, 44, 45 }; var ibw = EnumerativeBackgroundWorker.Make ( inputs, (i, c) => IterationResult.Make(i + 1, ProgressStatus.StepComplete) ); var nextResult = 0; ibw.OnIterationResult.Subscribe(r => nextResult = r.Data); ibw.Start(tokenSource); Thread.Sleep(100); Assert.AreEqual(ibw.CurrentInput, default(int)); Assert.AreEqual(ibw.CurrentIteration, inputs.Count()); Assert.AreEqual(ibw.TotalIterations, inputs.Count()); Assert.AreEqual(ibw.CurrentOutput, 46); }