Ejemplo n.º 1
0
        private static async Task <string> FirstStageAsync(string input)
        {
            try
            {
                if (Environment.TickCount % 10 == 0)
                {
                    throw new ArgumentOutOfRangeException("1st");
                }

                string data = $"{input} -> first stage";

                var message = Completeble.Create(data);
                _q1.Enqueue(message);               // enqueue and complete
                Console.Write(" 1st ");
                string result = await message.Task; // this is the magic
                Console.WriteLine($"\r\n{result}");
                return(result);
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine();
                Console.WriteLine(ex.Format(ErrorFormattingOption.FormatDuplication | ErrorFormattingOption.IncludeLineNumber));
                Console.ResetColor();
                throw;
            }
        }
Ejemplo n.º 2
0
        private static async Task LastStageAsync(Completeble <string> message)
        {
            try
            {
                await Task.Delay(1000);

                if (Environment.TickCount % 4 == 0)
                {
                    throw new ArgumentOutOfRangeException("4th");
                }

                string next = $"{message.Value} -> last stage";

                var nextMessage = message.ProceedWith(next);
                if (!nextMessage.TryComplete())
                {
                    Console.WriteLine("Completion failed (can only complete once)");
                }
            }
            catch (Exception ex)
            {
                // don't take the entire consumer down
                message.TryCompleteAsFaulted(ex);
            }
        }
Ejemplo n.º 3
0
        private static async Task <string> FirstStageAsync(string input)
        {
            string data = $"{input} -> first stage";

            var message = Completeble.Create(data);

            _firstQueue.Enqueue(message);       // enqueue and complete
            Console.Write(" 1st ");
            string result = await message.Task; // this is the magic

            Console.WriteLine($"\r\n{result}");
            return(result);
        }
Ejemplo n.º 4
0
        private static async Task ProcessFinalStageAsync(Completeble <string> message)
        {
            await Task.Delay(1000);

            string next = $"{message.Value} -> last stage";

            var nextMessage = message.ProceedWith(next);

            if (!nextMessage.TryComplete())
            {
                Console.WriteLine("Completion failed (can only complete once)");
            }
        }