public static async FAsync <int> TestDelayed()
        {
            _x = 1;
            await FSharpAsync.Sleep(0);

            return(0);
        }
        public static async FAsync <int> DelayAdditionAsAsync(int x, int y)
        {
            await FSharpAsync.Sleep(1);

            var sum = x + y;
            await FSharpAsync.Sleep(1);

            return(sum);
        }
        public static async FAsync <int> LongLoop()
        {
            for (var i = 0; i < 10000; i++)
            {
                await Task.Yield();

                await FSharpAsync.Sleep(0);
            }
            return(0);
        }
Beispiel #4
0
        public async void AsyncLambda()
        {
            var x = 0;

            Equal(x, 0);
            var t = new Task(() => { x = 1; });

            A0(async() => { await t; });
            await FSharpAsync.StartAsTask(FSharpAsync.Sleep(200), null, null);

            // await Task.Delay(200);
            Equal(x, 1);
        }
Beispiel #5
0
        public static FSharpAsync <Unit> Test(StreamSpan <byte[]> stream)
        {
            Log.Debug("Got this:{0}", stream.ToString());

            foreach (var streamEvent in stream.events)
            {
                FsCodec.Codec.
            }



            return(FSharpAsync.Sleep(1));
        }
        public static async FAsync <string> Thrower()
        {
            await FSharpAsync.Sleep(1);

            await Task.Delay(1);

            if (int.Parse("1") > 0)
            {
                throw new SpecialException("bad");
            }
            await Task.Delay(2);

            return("unreachable");
        }
Beispiel #7
0
        public void AsyncAsTaskWithCancellationTestAsync()
        {
            var cts = new CancellationTokenSource();

            var asy       = FSharpAsync.Sleep(500);
            var outerTask = asy.AsTask(cts.Token);

            // Force hard wait.
            Thread.Sleep(100);

            // Task cancelled.
            cts.Cancel();

            // Continuation point. (Will raise exception)
            Assert.ThrowsAsync <OperationCanceledException>(() => outerTask);
        }
Beispiel #8
0
        public async Task AsyncAsTaskWithCancellationTestAsync()
        {
            var cts = new CancellationTokenSource();

            var asy       = FSharpAsync.Sleep(500);
            var outerTask = asy.AsTask(cts.Token);

            // Force hard wait.
            Thread.Sleep(100);

            // Task cancelled.
            cts.Cancel();

            // Continuation point. (Will raise exception)
            await outerTask;

            Assert.Fail();
        }
        public static async FAsync <string> DirectThrowCatch()
        {
            await FSharpAsync.Sleep(1);

            string str = "unset";

            try
            {
                if (int.Parse("1") > 0)
                {
                    throw new SpecialException("direct");
                }
                str = "impossible";
            }
            catch (SpecialException ex) when(ex.Message == "direct")
            {
                str = "caught";
            }
            return(str);
        }
        public static async FAsync <string> Catcher()
        {
            await FSharpAsync.Sleep(1);

            await Task.Delay(1);

            string result;

            try
            {
                result = await Thrower();
            }
            catch (SpecialException ex) when(ex.Message == "bad")
            {
                result = "good";
            }
            catch (Exception)
            {
                Console.WriteLine("some other exn");
                result = "misc";
            }
            return(result);
        }
Beispiel #11
0
 public async Task AsyncGetAwaiterTestAsync()
 {
     var   asy = FSharpAsync.Sleep(500);
     await asy;
 }
Beispiel #12
0
 public async Task AsyncAsTaskTestAsync()
 {
     var asy = FSharpAsync.Sleep(500);
     await asy.AsTask();
 }