当前位置: 首页>>代码示例>>C#>>正文


C# Future.IsAvailable方法代码示例

本文整理汇总了C#中Future.IsAvailable方法的典型用法代码示例。如果您正苦于以下问题:C# Future.IsAvailable方法的具体用法?C# Future.IsAvailable怎么用?C# Future.IsAvailable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Future的用法示例。


在下文中一共展示了Future.IsAvailable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Should_pass_derived_types_through_the_filter

        public void Should_pass_derived_types_through_the_filter()
        {
            var received = new Future<bool>();

            Pipe consumer = PipeSegment.Consumer<BaseClass>(x => received.Complete(true));
            Pipe filter = PipeSegment.Filter<object>(consumer);

            filter.Send(new SubClass());

            received.IsAvailable(TimeSpan.Zero).ShouldBeTrue();
        }
开发者ID:KevM,项目名称:Magnum,代码行数:11,代码来源:Filter_Specs.cs

示例2: Should_not_stall_the_scheduler

        public void Should_not_stall_the_scheduler()
        {
            ActionQueue queue = new ThreadPoolActionQueue();
            ActionScheduler scheduler = new TimerActionScheduler(new ThreadPoolActionQueue());

            var called = new Future<bool>();

            scheduler.Schedule(200.Milliseconds(), queue, () => { throw new InvalidOperationException("Bugger!"); });
            scheduler.Schedule(400.Milliseconds(), queue, () => called.Complete(true));

            called.IsAvailable(1.Seconds()).ShouldBeTrue();
        }
开发者ID:xliang,项目名称:Magnum,代码行数:12,代码来源:ActionScheduler_Specs.cs

示例3: Should_schedule_events

        public void Should_schedule_events()
        {
            Channel<UserUpdate> channel = new SynchronousChannel<UserUpdate>();

            var update = new UserUpdate {LastActivity = DateTime.Now - 5.Minutes()};

            CommandQueue queue = new SynchronousCommandQueue();

            var scheduler = new ThreadPoolScheduler();

            var future = new Future<UserUpdate>();

            channel.Subscribe(queue, future.Complete);

            scheduler.Schedule(1000, () => channel.Publish(update));

            Thread.Sleep(500);

            Assert.IsFalse(future.IsAvailable(0.Seconds()));

            Assert.IsTrue(future.IsAvailable(1.Seconds()));
        }
开发者ID:xliang,项目名称:Magnum,代码行数:22,代码来源:Channel_Specs.cs

示例4: Should_wait_until_the_appropriate_time_for_the_action_to_execute

        public void Should_wait_until_the_appropriate_time_for_the_action_to_execute()
        {
            ActionQueue queue = new ThreadPoolActionQueue();
            ActionScheduler scheduler = new TimerActionScheduler(new SynchronousActionQueue());

            var called = new Future<bool>();

            scheduler.Schedule(100.Milliseconds(), queue, () => called.Complete(true));

            called.IsAvailable(0.Seconds()).ShouldBeFalse();

            called.IsAvailable(1.Seconds()).ShouldBeTrue();
        }
开发者ID:xliang,项目名称:Magnum,代码行数:13,代码来源:ActionScheduler_Specs.cs

示例5: Should_not_run_any_pending_actions

        public void Should_not_run_any_pending_actions()
        {
            ActionQueue queue = new ThreadPoolActionQueue();
            ActionScheduler scheduler = new TimerActionScheduler(new ThreadPoolActionQueue());

            var called = new Future<bool>();

            scheduler.Schedule(1.Seconds(), queue, () => called.Complete(true));

            scheduler.Disable();

            called.IsAvailable(2.Seconds()).ShouldBeFalse();
        }
开发者ID:xliang,项目名称:Magnum,代码行数:13,代码来源:ActionScheduler_Specs.cs

示例6: Should_prevent_new_actions_from_being_queued

        public void Should_prevent_new_actions_from_being_queued()
        {
            ActionQueue queue = new ThreadPoolActionQueue();

            var called = new Future<bool>();

            queue.StopAcceptingActions();

            Assert.Throws<ActionQueueException>(() => queue.Enqueue(() => called.Complete(true)));

            queue.ExecuteAll(10.Seconds());

            called.IsAvailable().ShouldBeFalse();
        }
开发者ID:xliang,项目名称:Magnum,代码行数:14,代码来源:ActionQueue_Specs.cs

示例7: Should_deliver_the_message_once_the_endpoint_is_available

        public void Should_deliver_the_message_once_the_endpoint_is_available()
        {
            var received = new Future<PingMessage>();

            using (RemoteBus.Subscribe<PingMessage>(received.Complete).Disposable())
            {
                Thread.Sleep(100);

                var ping = new PingMessage();
                LocalBus.Publish(ping);

                received.IsAvailable(5.Seconds()).ShouldBeTrue();
            }
        }
开发者ID:cstick,项目名称:MassTransit,代码行数:14,代码来源:DurablePublisher_Specs.cs

示例8: Should_filter_out_unwanted_messages

        public void Should_filter_out_unwanted_messages()
        {
            Channel<UserUpdate> channel = new SynchronousChannel<UserUpdate>();

            UserUpdate update = new UserUpdate {LastActivity = DateTime.Now - 5.Minutes()};

            CommandQueue queue = new SynchronousCommandQueue();

            var future = new Future<UserUpdate>();

            channel.Subscribe(queue, future.Complete, message => message.LastActivity > DateTime.Now);

            var result = channel.Publish(update);
            Assert.IsTrue(result);

            Assert.IsFalse(future.IsAvailable(1.Seconds()));
        }
开发者ID:xliang,项目名称:Magnum,代码行数:17,代码来源:Channel_Specs.cs

示例9: Should_invoke_the_continuation

		public void Should_invoke_the_continuation()
		{
			var transport = MockRepository.GenerateStub<IMsmqTransport>();
			transport.Stub(x => x.Receive(null))
				.Callback(new Func<Func<Message, Action<Message>>, bool>(Forwarder));

			var address = MockRepository.GenerateMock<IMsmqEndpointAddress>();

			IEndpoint endpoint = new MsmqEndpoint(address, new XmlMessageSerializer(), transport, MockRepository.GenerateMock<IMsmqTransport>());

			var future = new Future<object>();

			endpoint.Receive(m =>
			                 message =>
			                 	{
			                 		Assert.IsInstanceOf<SimpleMessage>(message);

			                 		Assert.AreEqual(((SimpleMessage) message).Name, "Chris");

			                 		future.Complete(message);
			                 	});

			Assert.IsTrue(future.IsAvailable(), "Receive was not called");
		}
开发者ID:hakeemsm,项目名称:MassTransit,代码行数:24,代码来源:ReceiveFromEndpoint_Specs.cs

示例10: Should_result_in_no_waiting_actions_in_the_queue

        public void Should_result_in_no_waiting_actions_in_the_queue()
        {
            TraceLogProvider.Configure(LogLevel.Debug);

            ActionQueue queue = new ThreadPoolActionQueue();

            queue.Enqueue(() => Thread.Sleep(1000));

            var called = new Future<bool>();

            queue.Enqueue(() => called.Complete(true));

            queue.ExecuteAll(8.Seconds());

            called.IsAvailable().ShouldBeTrue();
        }
开发者ID:xliang,项目名称:Magnum,代码行数:16,代码来源:ActionQueue_Specs.cs

示例11: Should_receive_the_message_when_a_transaction_is_rolled_back

		public void Should_receive_the_message_when_a_transaction_is_rolled_back()
		{
			var future = new Future<DeleteMessage>();

			using (TransactionScope transaction = new TransactionScope())
			{
				Endpoint.Receive(message => m => { future.Complete(m as DeleteMessage); });

				// do not complete the transaction (implicit rollback)
			}

			future.IsAvailable().ShouldBeTrue();

			Endpoint.ShouldContain<DeleteMessage>();
		}
开发者ID:KevM,项目名称:MassTransit,代码行数:15,代码来源:As_a_transactional_endpoint.cs

示例12: Should_receive_the_message_when_a_transaction_is_completed

		public void Should_receive_the_message_when_a_transaction_is_completed()
		{
			var future = new Future<DeleteMessage>();

			using (TransactionScope transaction = new TransactionScope())
			{
				Endpoint.Receive(message => m => { future.Complete(m as DeleteMessage); });

				transaction.Complete();
			}

			future.IsAvailable().ShouldBeTrue();
			Endpoint.ShouldNotContain<DeleteMessage>();
		}
开发者ID:KevM,项目名称:MassTransit,代码行数:14,代码来源:As_a_transactional_endpoint.cs

示例13: Should_work_for_thread_static_instances

        public void Should_work_for_thread_static_instances()
        {
            int message = 27;

            var result = MockRepository.GenerateMock<Channel<int>>();
            result.Expect(x => x.Send(message)).Repeat.Twice();

            var provider = MockRepository.GenerateMock<ChannelProvider<int>>();
            provider.Expect(x => x(message)).Return(result).Repeat.Twice();

            var channel = new InstanceChannel<int>(new ThreadStaticChannelProvider<int>(provider).GetChannel);

            Future<bool> first = new Future<bool>();
            Future<bool> second = new Future<bool>();

            ThreadPool.QueueUserWorkItem(x =>
                {
                    long k;
                    for (int i = 0; i < 10000000; i++)
                    {
                        k = i*777;

                    }
                    channel.Send(message);
                    first.Complete(true);
                });
            ThreadPool.QueueUserWorkItem(x =>
                {
                    long k;
                    for (int i = 0; i < 10000000; i++)
                    {
                        k = i * 777;

                    }
                    channel.Send(message);
                    second.Complete(true);
                });

            first.IsAvailable(5.Seconds()).ShouldBeTrue();
            second.IsAvailable(5.Seconds()).ShouldBeTrue();

            provider.VerifyAllExpectations();
            result.VerifyAllExpectations();
        }
开发者ID:xliang,项目名称:Magnum,代码行数:44,代码来源:ConsumerInstance_Specs.cs

示例14: Should_run_the_action_immediately

        public void Should_run_the_action_immediately()
        {
            ActionQueue queue = new ThreadPoolActionQueue();
            ActionScheduler scheduler = new TimerActionScheduler(new SynchronousActionQueue());

            var called = new Future<bool>();

            scheduler.Schedule(TimeSpan.Zero, queue, () => called.Complete(true));

            called.IsAvailable(1.Seconds()).ShouldBeTrue();
        }
开发者ID:xliang,项目名称:Magnum,代码行数:11,代码来源:ActionScheduler_Specs.cs

示例15: Should_run_the_action_until_disabled

        public void Should_run_the_action_until_disabled()
        {
            ActionQueue queue = new ThreadPoolActionQueue();
            ActionScheduler scheduler = new TimerActionScheduler(new ThreadPoolActionQueue());

            Stopwatch elapsed = Stopwatch.StartNew();

            int count = 0;
            var called = new Future<int>();
            var failed = new Future<bool>();

            ScheduledAction scheduledAction = null;
            scheduledAction = scheduler.Schedule(TimeSpan.Zero, 100.Milliseconds(), queue, () =>
                {
                    count++;
                    if (count == 10)
                    {
                        called.Complete(count);
                        scheduledAction.Cancel();
                    }
                    else if (count > 10)
                    {
                        failed.Complete(true);
                    }
                });

            called.IsAvailable(5.Seconds()).ShouldBeTrue();

            elapsed.Stop();

            failed.IsAvailable(200.Milliseconds()).ShouldBeFalse();

            Trace.WriteLine("Time Period: " + elapsed.ElapsedMilliseconds);
        }
开发者ID:xliang,项目名称:Magnum,代码行数:34,代码来源:ActionScheduler_Specs.cs


注:本文中的Future.IsAvailable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。