Example #1
0
 public static async Task MyIteratorMethod3(YieldEnumerator <int, string> e)
 {
     Console.WriteLine("A");
     Console.WriteLine(await e.YieldReturn(1));
     Console.WriteLine("B");
     Console.WriteLine(await e.YieldReturn(2));
     Console.WriteLine("C");
     Console.WriteLine(await e.YieldReturn(3));
     Console.WriteLine("D");
 }
Example #2
0
        public static async Task MyIteratorBroken3(YieldEnumerator <int, Unit> e)
        {
            await e.YieldReturn(1);

            if (DateTime.Now.Year < 10000)
            {
                throw new IOException("Bad");
            }

            await e.YieldReturn(2);
        }
Example #3
0
        public static async Task MyIteratorMethod1(YieldEnumerator <int, Unit> e)
        {
            Console.WriteLine("A");
            await e.YieldReturn(1);

            Console.WriteLine("B");
            await e.YieldReturn(2);

            Console.WriteLine("C");
            await e.YieldReturn(3);

            Console.WriteLine("D");
        }
Example #4
0
 public static async Task MyIteratorMethodInfinite(YieldEnumerator <int, Unit> e)
 {
     for (var n = 0; ; n++)
     {
         await e.YieldReturn(n);
     }
 }
Example #5
0
 public static async Task MyIteratorMethod4(YieldEnumerator <int, string> e)
 {
     try
     {
         Console.WriteLine("A");
         Console.WriteLine(await e.YieldReturn(1));
         Console.WriteLine("B");
         Console.WriteLine(await e.YieldReturn(2));
         Console.WriteLine("C");
         Console.WriteLine(await e.YieldReturn(3));
         Console.WriteLine("D");
     }
     catch (IOException x)
     {
         Console.WriteLine(x.Message);
     }
 }
Example #6
0
        public static async Task MyIteratorBroken1(YieldEnumerator <int, Unit> e)
        {
            // always happens, but compiler doesn't know that
            if (DateTime.Now.Year < 10000)
            {
                throw new IOException("Bad");
            }

            await e.YieldReturn(1);
        }
Example #7
0
        public static async Task MyIteratorMethod2(YieldEnumerator <int, Unit> e)
        {
            try
            {
                Console.WriteLine("A");
                await e.YieldReturn(1);

                Console.WriteLine("B");
                await e.YieldReturn(2);

                Console.WriteLine("C");
                await e.YieldReturn(3);

                Console.WriteLine("D");
            }
            finally
            {
                Console.WriteLine("Running finally");
            }
        }