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


C# Future.Complete方法代码示例

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


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

示例1: An_exception_is_thrown

        public void An_exception_is_thrown()
        {
            var future = new Future<object>();

            var obj1 = new object();
            var obj2 = new object();

            future.Complete(obj1);
            Assert.That(() => future.Complete(obj2), Throws.TypeOf<InvalidOperationException>());
        }
开发者ID:hakeemsm,项目名称:Magnum,代码行数:10,代码来源:Future_Specs.cs

示例2: 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

示例3: 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

示例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: 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

示例6: 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

示例7: InvokesOnCompletesWhenCompleted

 public void InvokesOnCompletesWhenCompleted () {
     var f = new Future<object>();
     object completeResult = null;
     f.RegisterOnComplete((_) => { completeResult = _.Error ?? _.Result; });
     f.Complete(5);
     Assert.AreEqual(5, completeResult);
 }
开发者ID:mbahar94,项目名称:fracture,代码行数:7,代码来源:FutureTests.cs

示例8: Read

 public Future<int> Read (byte[] buffer, int offset, int count) {
     var f = new Future<int>();
     if (!_Socket.Connected) {
         if (ThrowOnDisconnect)
             f.Fail(new SocketDisconnectedException());
         else
             f.Complete(0);
     } else {
         SocketError errorCode;
         if (_Socket.Available >= count) {
             try {
                 int bytesRead = _Socket.Receive(buffer, offset, count, SocketFlags.None, out errorCode);
                 if (ThrowOnDisconnect && (bytesRead == 0)) {
                     f.Fail(new SocketDisconnectedException());
                 } else {
                     f.Complete(bytesRead);
                 }
             } catch (Exception ex) {
                 f.Fail(ex);
             }
         } else {
             _Socket.BeginReceive(buffer, offset, count, SocketFlags.None, out errorCode, _ReadCallback, f);
         }
     }
     return f;
 }
开发者ID:mbahar94,项目名称:fracture,代码行数:26,代码来源:Sockets.cs

示例9: 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

示例10: 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

示例11: 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

示例12: A_loopback_registry

		public void A_loopback_registry()
		{
			Address = new Uri("loopback://localhost/");
			ReceivedA = new Future<A>();

			Registry = ActorRegistryFactory.New(x =>
			{
				x.Remote(r =>
				{
					r.ListenTo(Address);
				});
			});

			ActorId = Guid.NewGuid();
			Actor = AnonymousActor.New(inbox =>
			{
				inbox.Loop(loop =>
				{
					loop.Receive<Message<A>>(message =>
					{
						ReceivedA.Complete(message.Body);

						loop.Continue();
					});
				});
			});

			Registry.Register(ActorId, Actor);
		}
开发者ID:Nangal,项目名称:Stact,代码行数:29,代码来源:LoopbackRegistry_Specs.cs

示例13: SomeActorInstance

		public SomeActorInstance()
		{
			_fiber = new PoolFiber();
			_future = new Future<MyMessage>();

			MessageChannel = new ConsumerChannel<MyMessage>(_fiber, Consume);
			LambdaMessageChannel = new ConsumerChannel<MyMessage>(_fiber, message => _future.Complete(message));
		}
开发者ID:Nangal,项目名称:Stact,代码行数:8,代码来源:ChannelQueue_Specs.cs

示例14: ConfigureServiceBus

        protected override void ConfigureServiceBus(Uri uri, ServiceBusConfigurator configurator)
        {
            base.ConfigureServiceBus(uri, configurator);

            _received = new Future<A>();

            configurator.Subscribe(x => { x.Handler<A>(msg => _received.Complete(msg)); });
        }
开发者ID:rajwilkhu,项目名称:MassTransit,代码行数:8,代码来源:Bytes_Specs.cs

示例15: ConfigureServiceBus

        protected override void ConfigureServiceBus(Uri uri, ServiceBusConfigurator configurator)
        {
            _received = new Future<A>();

            configurator.Subscribe(s => s.Handler<A>(message => _received.Complete(message)));
            configurator.UseControlBus();
            configurator.UseStomp();
        }
开发者ID:haf,项目名称:MassTransit-Stomp,代码行数:8,代码来源:message_publishing.cs


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