Created
March 19, 2025 16:06
-
-
Save Aaronontheweb/99372942bf4eaf6e3560a1cf1036fdfa to your computer and use it in GitHub Desktop.
SelectAsync Akka.NET v1.5.39 Reproduction Attempt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var actorSystem = ActorSystem.Create("Foo"); | |
async Task DoCount(int parallelism, int elements, bool configureAwait) | |
{ | |
Console.WriteLine($"[{DateTime.UtcNow}] Starting calculation of [{elements}] elements with parallelism [{parallelism}]"); | |
var timer = Stopwatch.StartNew(); | |
var total = await Source.Repeat(1) | |
.SelectAsync(10, async i => | |
{ | |
var delayFactor = ThreadLocalRandom.Current.Next(1, 10); | |
if(delayFactor % 3 == 0){ | |
await Task.Delay(delayFactor).ConfigureAwait(configureAwait); | |
} | |
return i; | |
}) | |
.Take(elements) | |
.RunAggregate(0, (tot, i) => tot += 1, actorSystem); | |
timer.Stop(); | |
Console.WriteLine($"[{DateTime.UtcNow}] Finished of [{elements}] with parallelism [{parallelism}] in {timer.Elapsed}"); | |
} | |
async Task RunForConfigureAwait(bool configureAwait) | |
{ | |
Console.WriteLine($"#### BEGIN ConfigureAwait({configureAwait}) ####"); | |
await DoCount(1, 100, configureAwait); | |
await DoCount(10, 100, configureAwait); | |
await DoCount(100, 100, configureAwait); | |
await DoCount(10, 1000, configureAwait); | |
await DoCount(15, 5000, configureAwait); | |
await DoCount(25, 10_000, configureAwait); | |
await DoCount(100, 10_000, configureAwait); | |
Console.WriteLine($"#### END ConfigureAwait({configureAwait}) ####"); | |
} | |
await RunForConfigureAwait(true); | |
Console.WriteLine(Environment.NewLine); | |
await RunForConfigureAwait(false); | |
await actorSystem.Terminate(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment