Beispiel #1
0
        public void EnqueueTypeTest()
        {
            var myFiber = new MessageFiber();

            //an action
            myFiber.EnqueueAction(() => { });
            //a task
            myFiber.EnqueueTask(new Task(() => { }));
            //a task<T>
            myFiber.EnqueueTask(new Task <int>(() => 0));
        }
Beispiel #2
0
        public async Task TaskFiberSpeedTest()
        {
            //this test is to examine the actions are executed in thread safe manner in threadpool
            var tmf    = new MessageFiber();
            var intVal = 0;
            var add    = MultiThreadTest.RunMultiple(() => tmf.EnqueueAction(() => intVal++), 100000);
            var minus  = MultiThreadTest.RunMultiple(() => tmf.EnqueueAction(() => intVal--), 100000);
            await Task.WhenAll(add);

            await Task.WhenAll(minus);

            //this await anything in this fiber
            await tmf;

            //the i variable must be 0, and exception count should be zero too
            Assert.True(intVal == 0);
        }