Example #1
0
        public Task AsyncUnsubscribeCheck()
        {
            using AsyncTester test = new AsyncTester();
            IDisposable sub = _eventHub.Subscribe(test.Fiber, test);

            _eventHub.Publish(3);

            sub.Dispose();
            Assert.IsFalse(_eventHub.HasSubscriptions <int>());
            return(Task.CompletedTask);
        }
Example #2
0
        public async Task Async()
        {
            using AsyncTester test = new AsyncTester();
            using IDisposable sub  = _eventHub.Subscribe(test.Fiber, test);

            _eventHub.Publish(3);
            _eventHub.Publish(2);
            _eventHub.Publish("test");

            await Task.Delay(100);

            Assert.AreEqual(6, test.Count);
        }
Example #3
0
        public static void RunTests()
        {
            //IO Bound Tasks

            //Not very efficient, you are creating a thread and making it useless untill it finishes downloading
            Task <string> downloadTask = DownloadWebPageAsync("https://www.w3schools.com");

            while (!downloadTask.IsCompleted)
            {
                Console.WriteLine(".");
                Thread.Sleep(250);
            }

            Console.WriteLine(downloadTask.Result);

            AsyncTester atest = new AsyncTester();

            atest.RunIt(new object(), null);

            Console.ReadLine();
        }