예제 #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;
            }
        }
예제 #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);
            }
        }
예제 #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);
        }
예제 #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)");
            }
        }