Пример #1
0
        public void CreateFutureSetAndGetValue()
        {
            Future future = new Future();

            future.SetValue(1);

            object result = future.GetValue();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result);

            result = future.GetValue();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result);
        }
Пример #2
0
        public void CreateFutureGetAndSetValue()
        {
            Future future = new Future();
            ManualResetEvent handle = new ManualResetEvent(false);
            bool executed = false;

            Thread thread = new Thread(new ThreadStart(() => { handle.WaitOne(); executed = true;  future.SetValue(1); }));
            thread.Start();

            Assert.IsFalse(executed);
            Thread.Sleep(100);
            Assert.IsFalse(executed);

            handle.Set();

            object result = future.GetValue();
            Assert.IsTrue(executed);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result);
        }