public ChannelReader <string> In(ChannelReader <string> input) { Task.Run(async() => { await foreach (var element in input.ReadAllAsync()) { var _ = Task.Run(async() => { var results = await Task.WhenAll( Enumerable .Range(0, _range) .Select(i => Signers.DataSignerCrc32(i.ToString() + element)) ); await _outPutChannel.Writer.WriteAsync(string.Concat(results)); }); } }); return(_outPutChannel.Reader); }
public IEnumerable <string> In(IEnumerable <string> input) { Task.Run(() => { foreach (var element in input) { Task.Run(async() => { var results = await Task.WhenAll( Enumerable .Range(0, _range) .Select(i => Signers.DataSignerCrc32(i.ToString() + element)) ); _outPutStream.Add(string.Concat(results)); }); } }); return(_outPutStream.GetConsumingEnumerable()); }
public IEnumerable <string> In(IEnumerable <string> input) { Task.Run(async() => { foreach (var element in input) { var rightSideNotCompleted = await Signers.DataSignerMd5(element); var _ = Task.Run(async() => { _outPutStream.Add( string.Join("~", await Task.WhenAll( Signers.DataSignerCrc32(element), Signers.DataSignerCrc32(rightSideNotCompleted) ) ) ); }); } }); return(_outPutStream.GetConsumingEnumerable()); }
public ChannelReader <string> In(ChannelReader <string> input) { Task.Run(async() => { await foreach (var element in input.ReadAllAsync()) { var rightSideNotCompleted = await Signers.DataSignerMd5(element); var _ = Task.Run(async() => { await _outPutChannel.Writer.WriteAsync( string.Join("~", await Task.WhenAll( Signers.DataSignerCrc32(element), Signers.DataSignerCrc32(rightSideNotCompleted) ) ) ); }); } }); return(_outPutChannel.Reader); }
public void AkkaStreams() { var counter = 0; var singleHash = Flow.FromGraph(GraphDsl.Create(builder => { var broadCast = builder.Add(new Broadcast <string>(2)); var zip = builder.Add(new Zip <string, string>()); var left = Flow.Create <string>().SelectAsync(InputElements, async i => await Signers.DataSignerCrc32(i)); var right = Flow.Create <string>() .SelectAsync(1, Signers.DataSignerMd5) .SelectAsync(InputElements, Signers.DataSignerCrc32); builder.From(broadCast.Out(0)).Via(left).To(zip.In0); builder.From(broadCast.Out(1)).Via(right).To(zip.In1); return(new FlowShape <string, (string, string)>(broadCast.In, zip.Out)); })); var mergeSingleHash = Flow.Create <(string, string)>() .Select(tuple => string.Join("~", tuple.Item1, tuple.Item2)); var multiHash = Flow.Create <string>() .SelectAsync(InputElements, async input => await Task.WhenAll(Enumerable.Range(0, 6).Select(i => Signers.DataSignerCrc32(i.ToString() + input)))) .Select(string.Concat); var combine = Flow.Create <string>() .Grouped(CombineBy) .Select(i => string.Join("_", i)); Source.From(Enumerable.Range(0, InputElements)) .Select(i => i.ToString()) .Via(singleHash) .Via(mergeSingleHash) .Via(multiHash) .Via(combine) .To(Sink.ForEach <string>(i => { counter++; if (counter == InputElements / CombineBy) { ManualResetSlimForAkka.Set(); } })) .Run(Materializer); ManualResetSlimForAkka.Wait(); ManualResetSlimForAkka.Reset(); }
public static async Task AkkaStreams() { var stopWatch = new Stopwatch(); const string akkaConfig = @" akka { loggers = [""Akka.Event.DefaultLogger""] } "; using var system = ActorSystem.Create("hashing", ConfigurationFactory.ParseString(akkaConfig)); using var materializer = system.Materializer(); using var manualResetSlim = new ManualResetEventSlim(); stopWatch.Start(); var counter = 0; var singleHash = Flow.FromGraph(GraphDsl.Create(builder => { var broadCast = builder.Add(new Broadcast <string>(2)); var zip = builder.Add(new Zip <string, string>()); var left = Flow.Create <string>().SelectAsync(InputElements, async i => await Signers.DataSignerCrc32(i)); var right = Flow.Create <string>() .SelectAsync(1, Signers.DataSignerMd5) .SelectAsync(InputElements, Signers.DataSignerCrc32); builder.From(broadCast.Out(0)).Via(left).To(zip.In0); builder.From(broadCast.Out(1)).Via(right).To(zip.In1); return(new FlowShape <string, (string, string)>(broadCast.In, zip.Out)); })); var mergeSingleHash = Flow.Create <(string, string)>() .Select(tuple => string.Join("~", tuple.Item1, tuple.Item2)); var multiHash = Flow.Create <string>() .SelectAsync(InputElements, async input => await Task.WhenAll(Enumerable.Range(0, 6).Select(i => Signers.DataSignerCrc32(i.ToString() + input)))) .Select(string.Concat); var combine = Flow.Create <string>() .Grouped(CombineBy) .Select(i => string.Join("_", i)); Source.From(Enumerable.Range(0, InputElements)) .Select(i => i.ToString()) .Via(singleHash) .Via(mergeSingleHash) .Via(multiHash) .Via(combine) .To(Sink.ForEach <string>(i => { counter++; Console.WriteLine(i); if (counter == InputElements / CombineBy) { manualResetSlim.Set(); } })) .Run(materializer); manualResetSlim.Wait(); stopWatch.Stop(); Console.Out.WriteLine($"\n\n Elapsed {stopWatch.Elapsed}... \n\n"); }