Example #1
0
        public async Task AsyncConsumer_SimplyCalls_Ctor_Supplied_Func()
        {
            var called         = 0;
            var funcSubstitute = new Func <object, CancellationToken, Task>((f, t) =>
            {
                Interlocked.Increment(ref called);
                return(Task.CompletedTask);
            });

            using (var producer = new AsyncConsumer <object>(funcSubstitute))
            {
                Assert.True(producer.InitAsync().Equals(Task.CompletedTask));
                await producer.ConsumeAsync(null, CancellationToken.None);

                Assert.True(called == 1);
            }
        }
Example #2
0
        public async Task <int> Test()
        {
            int largestNumber = int.MinValue;

            var producer = Factory.CreateProducer(testData);

            var webReader = new AsyncConsumer <int, int>()
            {
                OperationCooldown = 100,
                AsyncOperation    = async(x) =>
                {
                    string result = await GetStringAsync(x);

                    string[] lines = result.Split('\n');

                    int[] numbers = lines.Where(x => x.Length > 1).Select(x => int.Parse(x)).ToArray();

                    foreach (var item1 in numbers)
                    {
                        if (item1 > largestNumber)
                        {
                            largestNumber = item1;
                        }
                    }

                    return(largestNumber);
                }
            };

            webReader.InputFrom(producer);
            webReader.ObserveCollection(producer);

            await Task.WhenAll(producer.ProduceAsync(), webReader.ConsumeAsync());

            Console.WriteLine("//////////////////////////// = " + largestNumber);

            return(largestNumber);
        }