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


C# Future.WaitUntilCompleted方法代码示例

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


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

示例1: Should_have_the_bits_without_the_message_first

		public void Should_have_the_bits_without_the_message_first()
		{
			var engine = new DynamicRoutingEngine(new PoolFiber());
			var visualizer = new TraceRoutingEngineVisualizer();

			var received = new Future<A>();
			engine.Configure(x => x.Receive<A>(received.Complete));

			var block = new Future<int>();
			engine.Add(0, () =>
				{
					visualizer.Show(engine);
					block.Complete(0);
				});
			block.WaitUntilCompleted(2.Seconds());

			engine.Send(new A());
			received.WaitUntilCompleted(2.Seconds());

			engine.Send(new B());

			var receivedB = new Future<B>();
			engine.Configure(x => x.Receive<B>(receivedB.Complete));

			received.WaitUntilCompleted(8.Seconds()).ShouldBeTrue();
			receivedB.WaitUntilCompleted(8.Seconds()).ShouldBeTrue();

			//engine.Receive<A, B>(x => { });

			visualizer.Show(engine);
		}
开发者ID:Nangal,项目名称:Stact,代码行数:31,代码来源:Visualizer_Specs.cs

示例2: Should_publish_to_non_transactional_queue

        public void Should_publish_to_non_transactional_queue()
        {
            using (IServiceBus transactionalBus = ServiceBusFactory.New(x =>
                {
                    x.UseMsmq();
                    x.ReceiveFrom(_transactionalUri);
                    x.UseMulticastSubscriptionClient();
                    x.SetCreateMissingQueues(true);
                    x.SetCreateTransactionalQueues(true);
                }))
            {
                using (IServiceBus nonTransactionalBus = ServiceBusFactory.New(x =>
                    {
                        x.UseMsmq();
                        x.ReceiveFrom(_nonTransactionalUri);
                        x.UseMulticastSubscriptionClient();
                        x.SetCreateMissingQueues(true);
                        x.SetCreateTransactionalQueues(false);
                    }))
                {
                    var future = new Future<MyMessage>();

                    nonTransactionalBus.SubscribeHandler<MyMessage>(future.Complete);

                    transactionalBus.ShouldHaveSubscriptionFor<MyMessage>();

                    transactionalBus.Publish(new MyMessage(),
                        ctx => ctx.IfNoSubscribers(() => { throw new Exception("NoSubscribers"); }));

                    future.WaitUntilCompleted(8.Seconds()).ShouldBeTrue("The published message was not received>");
                }
            }
        }
开发者ID:rkenning,项目名称:MassTransit,代码行数:33,代码来源:TransactionalToNonTransactional_Specs.cs

示例3: Should_properly_arrive_at_the_destination

		public void Should_properly_arrive_at_the_destination()
		{
			var serviceUri = new Uri("net.pipe://localhost/pipe");
			string pipeName = "test";

			var future = new Future<TestMessage>();
			var message = new TestMessage
				{
					Id = Guid.NewGuid(),
					Name = "Alpha",
				};

			UntypedChannel adapter = new ChannelAdapter();
			using (var remote = new WcfChannelHost(new SynchronousFiber(), adapter, serviceUri, pipeName))
			{
				using (adapter.Connect(x =>
					{
						x.AddConsumerOf<TestMessage>()
							.UsingConsumer(m => future.Complete(m));
					}))
				{
					var client = new WcfChannelProxy(new SynchronousFiber(), serviceUri, pipeName);

					client.Send(message);

					future.WaitUntilCompleted(2.Seconds()).ShouldBeTrue();
				}
			}

			future.Value.ShouldNotBeNull();
			future.Value.ShouldEqual(message);
			future.Value.ShouldNotBeTheSameAs(message);
		}
开发者ID:Nangal,项目名称:Stact,代码行数:33,代码来源:RemoteChannel_Specs.cs

示例4: Should_support_the_username_password_for_a_host

        public void Should_support_the_username_password_for_a_host()
        {
            var inputAddress = new Uri("rabbitmq://localhost/mt/test_queue");
            var future = new Future<IConsumeContext<A>>();

            using (IServiceBus bus = ServiceBusFactory.New(c =>
                {
                    c.ReceiveFrom(inputAddress);
                    c.UseRabbitMq(r =>
                        {
                            r.ConfigureHost(inputAddress, h =>
                                {
                                    h.SetUsername("testUser");
                                    h.SetPassword("test");
                                });
                        });

                    c.Subscribe(s => s.Handler<A>((context, message) => future.Complete(context)));
                }))
            {
                bus.Publish(new A());

                Assert.IsTrue(future.WaitUntilCompleted(TimeSpan.FromSeconds(8)));
            }

            Assert.AreEqual(inputAddress.ToString(), future.Value.SourceAddress.ToString());
        }
开发者ID:cstick,项目名称:MassTransit,代码行数:27,代码来源:Security_Specs.cs

示例5: Should_be_fast

        public void Should_be_fast()
        {
            Fiber fiber = new ThreadPoolFiber();

            const int limit = 5000000;

            var complete = new Future<int>();

            Channel<MsgStruct> channel = new ConsumerChannel<MsgStruct>(fiber, message =>
                {
                    if (message.Count == limit)
                        complete.Complete(limit);
                });

            using (var timer = new FunctionTimer("Throughput", x =>
                {
                    Trace.WriteLine("Time to execute: " + (int) x.ElapsedMilliseconds + "ms");

                    Trace.WriteLine("Per second throughput: " + (int) (limit/(x.ElapsedMilliseconds/1000)));
                }))
            {
                for (int i = 1; i <= limit; i++)
                {
                    channel.Send(new MsgStruct
                        {
                            Count = i,
                            Other = i*8,
                        });
                }

                timer.Mark();

                complete.WaitUntilCompleted(30.Seconds()).ShouldBeTrue();
            }
        }
开发者ID:neouser99,项目名称:Magnum,代码行数:35,代码来源:ChannelPerformance_Specs.cs

示例6: Adding_operations_to_a_fiber

		public void Adding_operations_to_a_fiber()
		{
			_count = 10000;
			_values = new int[_count];
			Fiber fiber = new PoolFiber();

			int index = 0;
			var completed = new Future<int>();

			var go = new Future<bool>();

			fiber.Add(() => { go.WaitUntilCompleted(10.Seconds()); });

			for (int i = 0; i < _count; i++)
			{
				int offset = i;
				fiber.Add(() =>
					{
						_values[offset] = index++;

						if (offset == _count - 1)
							completed.Complete(offset);
					});
			}

			go.Complete(true);

			completed.WaitUntilCompleted(10.Seconds()).ShouldBeTrue();
		}
开发者ID:Nangal,项目名称:Stact,代码行数:29,代码来源:OrderedOperation_Specs.cs

示例7: query_internal_state

 protected static EventHeapState query_internal_state()
 {
     var reply = new Future<EventHeapState>();
     AnonymousActor.New(inbox => eventFilter.Request<QueryInternals>(inbox).Receive<EventHeapState>(msg => reply.Complete(msg)));
     reply.WaitUntilCompleted(-1);
     return reply.Value;
 }
开发者ID:haf,项目名称:ReceiverSpike,代码行数:7,代码来源:heap_internal_state_context.cs

示例8: A_file_is_created

        public void A_file_is_created()
        {
            _baseDirectory = AppDomain.CurrentDomain.BaseDirectory;

            _filename = "test2.dat";
            _path = Path.Combine(_baseDirectory, _filename);

            System.IO.File.Delete(_path);

            _listener = new Future<FileCreated>();

            _channel = new ChannelAdapter();
            FiberFactory fiberFactory = () => new SynchronousFiber();
            _scheduler = new TimerScheduler(fiberFactory());
            _producer = new PollingFileSystemEventProducer(_baseDirectory, _channel, _scheduler, fiberFactory(),
                                                           20.Seconds());

            Thread.Sleep(5.Seconds());

            using (_channel.Connect(x => x.AddConsumerOf<FileCreated>().UsingConsumer(m => _listener.Complete(m))))
            {
                System.IO.File.Create(_path);

                _listener.WaitUntilCompleted(25.Seconds());
            }

            _producer.Dispose();
        }
开发者ID:sdhjl2000,项目名称:Magnum,代码行数:28,代码来源:PollingFileSystemWatcher_Specs.cs

示例9: Should_property_adapt_itself_to_a_channel_network

        public void Should_property_adapt_itself_to_a_channel_network()
        {
            TraceLogger.Configure(LogLevel.Debug);
            ILogger log = Logger.GetLogger<Sending_a_message_through_a_wcf_channel>();
            log.Debug("Starting");

            var serviceUri = new Uri("net.pipe://localhost/Pipe");
            string pipeName = "Test";
            Channel<TestMessage> adapter = new ChannelAdapter<TestMessage>();
            using (var host = new WcfChannelHost<TestMessage>(adapter, serviceUri, pipeName))
            {
                log.Debug("Host started");

                var future = new Future<TestMessage>();

                using (adapter.Connect(x =>
                    {
                        x.AddConsumer(m =>
                            {
                                log.Debug(l => l.Write("Received: {0}", m.Value));
                                future.Complete(m);
                            });
                    }))
                {
                    var client = new WcfChannelProxy<TestMessage>(new SynchronousFiber(), serviceUri, pipeName);
                    log.Debug("Client started");

                    client.Send(new TestMessage("Hello!"));

                    future.WaitUntilCompleted(2.Seconds()).ShouldBeTrue();

                    log.Debug("Complete");
                }
            }
        }
开发者ID:sdhjl2000,项目名称:Magnum,代码行数:35,代码来源:DubSeeEff_Specs.cs

示例10: Run

		public void Run()
		{
			Stopwatch timer = Stopwatch.StartNew();

			const int channelCount = 10000;
			const int seedCount = 500;

			var channels = new UntypedChannel[channelCount];
			var connections = new ChannelConnection[channelCount];

			var complete = new Future<int>();

			var latch = new CountdownLatch(channelCount*seedCount, complete.Complete);

			for (int i = 0; i < channelCount; i++)
			{
				int channelNumber = i;
				channels[i] = new ChannelAdapter();
				connections[i] = channels[i].Connect(x =>
					{
						x.AddConsumerOf<AMessage>()
							.UsingConsumer(message =>
								{
									if (channelNumber < channels.Length - 1)
										channels[channelNumber + 1].Send(message);

									latch.CountDown();
								});
					});
			}

			var body = new AMessage();

			for (int i = 0; i < seedCount; i++)
			{
				channels[i].Send(body);

				for (int j = 0; j < i; j++)
					latch.CountDown();
			}

			bool completed = complete.WaitUntilCompleted(2.Minutes());

			timer.Stop();

			connections.Each(x => x.Dispose());
			

			if (!completed)
			{
				Console.WriteLine("Process did not complete");
				return;
			}

			Console.WriteLine("Processed {0} messages in with {1} channels in {2}ms", seedCount, channelCount,
			                  timer.ElapsedMilliseconds);

			Console.WriteLine("That's {0} messages per second!", ((long)seedCount*channelCount*1000)/timer.ElapsedMilliseconds);
		}
开发者ID:Nangal,项目名称:Stact,代码行数:59,代码来源:ChannelAdapterBenchmark.cs

示例11: Should_properly_wrap_the_channel_as_synchronized

		public void Should_properly_wrap_the_channel_as_synchronized()
		{
			Assert.IsNull(SynchronizationContext.Current);

			var fiber = new PoolFiber();

			var input = new ChannelAdapter();

			var context = new TestSynchronizationContext();

			var future = new Future<TestMessage>();

			SynchronizationContext.SetSynchronizationContext(context);

			Assert.IsNotNull(SynchronizationContext.Current);

			using (input.Connect(x =>
				{
					x.AddConsumerOf<TestMessage>()
						.OnCurrentSynchronizationContext()
						.UsingConsumer(message =>
							{
								Trace.WriteLine("Received on Thread: " + Thread.CurrentThread.ManagedThreadId);

								Assert.IsNotNull(SynchronizationContext.Current);
								Assert.AreEqual(context, SynchronizationContext.Current);

								future.Complete(message);
							});
				}))
			{
				Trace.WriteLine("Subscribed on Thread: " + Thread.CurrentThread.ManagedThreadId);

				SynchronizationContext.SetSynchronizationContext(null);

				input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
					{
						typeof(ChannelAdapter),
						typeof(BroadcastChannel),
						typeof(TypedChannelAdapter<TestMessage>),
						typeof(SynchronizedChannel<TestMessage>),
						typeof(ConsumerChannel<TestMessage>),
					});

				fiber.Add(() =>
					{
						Trace.WriteLine("Thread: " + Thread.CurrentThread.ManagedThreadId);
						Assert.IsNull(SynchronizationContext.Current);

						input.Send(new TestMessage());
					});

				Assert.IsNull(SynchronizationContext.Current);

				future.WaitUntilCompleted(2.Seconds()).ShouldBeTrue();
			}
		}
开发者ID:Nangal,项目名称:Stact,代码行数:57,代码来源:SynchronizationContext_Specs.cs

示例12: Should_schedule_events

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

            Fiber fiber = new SynchronousFiber();

            var future = new Future<UserUpdate>();

            Channel<UserUpdate> channel = new PublishSubscribeChannel<UserUpdate>(fiber, new Channel<UserUpdate>[] {future});

            var scheduler = new TimerFiberScheduler(fiber);

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

            Thread.Sleep(500);

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

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

示例13: Should_not_pass_unwanted_types_through_the_filter

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

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

            filter.Send(new BaseClass());

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

示例14: Should_not_stall_the_scheduler

        public void Should_not_stall_the_scheduler()
        {
            Fiber fiber = new ThreadPoolFiber();
            Scheduler scheduler = new TimerScheduler(new ThreadPoolFiber());

            var called = new Future<bool>();

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

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

示例15: Should_receive_byte_array

        public void Should_receive_byte_array()
        {
            _received = new Future<A>();
            _sent = new A
                {
                    Contents = new byte[] {0x56, 0x34, 0xf3}
                };

            LocalBus.Endpoint.Send(_sent);

            _received.WaitUntilCompleted(8.Seconds()).ShouldBeTrue();
        }
开发者ID:cstick,项目名称:MassTransit,代码行数:12,代码来源:Bytes_Specs.cs


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