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


C# Future类代码示例

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


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

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

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

示例3: RequestingValueAfterSourceHasDataPerformsTransformation

 public void RequestingValueAfterSourceHasDataPerformsTransformation()
 {
     Future<string> source = new Future<string>();
     FutureProxy<int> subject = FutureProxy<int>.FromFuture(source, x => x.Length);
     source.Value = "hello";
     Assert.AreEqual(5, subject.Value);
 }
开发者ID:dioptre,项目名称:nkd,代码行数:7,代码来源:FutureProxyTest.cs

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

示例5: AttachToStack

        public void AttachToStack(CardStack s, Future IsLocalPlayer)
        {
            var c = this;

            if (c.CurrentStack != null)
            {
                c.CurrentStack.Cards.Remove(c);
            }

            c.PreviousStack = c.CurrentStack;
            c.CurrentStack = s;

            s.Cards.Add(c);

            if (this.Moved != null)
                this.Moved();

            // if the IsLocalPlayer is null then we are not meant to raise MovedByLocalPlayer
            if (IsLocalPlayer != null)
                IsLocalPlayer.Continue(
                    delegate
                    {
                        if (this.MovedByLocalPlayer != null)
                            this.MovedByLocalPlayer();
                    }
                );
        }
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:27,代码来源:Card.cs

示例6: A_single_registered_service_throws_on_start

        public void A_single_registered_service_throws_on_start()
        {
            _future = new Future<Exception>();
            ServiceCoordinator.ShelfFaulted += _future.Complete;
            IList<Func<IServiceController>> services = new List<Func<IServiceController>>
                {
                    () => new ServiceController<TestService>("test", WellknownAddresses.GetServiceCoordinatorProxy())
                        {
                            BuildService = s => new TestService(),
                            StartAction = x => { throw new Exception(); },
                            StopAction = x => x.Stop(),
                            ContinueAction = x => x.Continue(),
                            PauseAction = x => x.Pause()
                        },
                    () => new ServiceController<TestService>("test2", WellknownAddresses.GetServiceCoordinatorProxy())
                        {
                            BuildService = s => new TestService(),
                            StartAction = x => x.Start(),
                            StopAction = x => x.Stop(),
                            ContinueAction = x => x.Continue(),
                            PauseAction = x => x.Pause()
                        }
                };

            ServiceCoordinator.RegisterServices(services);

            ServiceCoordinator.Start();
        }
开发者ID:paulbatum,项目名称:Topshelf,代码行数:28,代码来源:Given_a_partially_failing_start_event.cs

示例7: Subject

			public Subject()
			{
				FutureA = new Future<Message<A>>();
				FutureB = new Future<Message<B>>();
				FutureC = new Future<Message<C>>();
				FutureD = new FutureChannel<Message<D>>();
			}
开发者ID:Nangal,项目名称:Stact,代码行数:7,代码来源:Convention_Specs.cs

示例8: A_request_is_sent_via_wcf

        public void A_request_is_sent_via_wcf()
        {
            _pipeUri = new Uri("net.pipe://localhost/pipe");

            _response = new Future<Response<TestMessage>>();

            _client = new ChannelAdapter();
            _clientConnection = _client.Connect(x =>
                {
                    x.SendToWcfChannel(_pipeUri, _pipeName)
                        .HandleOnCallingThread();

                    x.AddConsumerOf<Response<TestMessage>>()
                        .UsingConsumer(_response.Complete);
                });

            _server = new ChannelAdapter();
            _serverConnection = _server.Connect(x =>
                {
                    x.ReceiveFromWcfChannel(_pipeUri, _pipeName);

                    x.AddConsumerOf<Request<TestMessage>>()
                        .UsingConsumer(request => request.Respond(request.Body));
                });
        }
开发者ID:rickj33,项目名称:Stact,代码行数:25,代码来源:RequestWcf_Specs.cs

示例9: GetStockDetailsTest

        public GetStockDetailsTest()
        {
            this.symbol = "AnySymbol";
            this.detail = new Future<StockDetailModel>();

            this.stockService = new Mock<IStockService>();
        }
开发者ID:mmarkovic,项目名称:StockTicker,代码行数:7,代码来源:GetStockDetailsTest.cs

示例10: ConductDefaultContent

        public static IActionBuilder ConductDefaultContent(this IActionBuilder builder, Conductor<IStockTickerContentViewModel> conductor)
        {
            var future = new Future<StockDetailModel>();
            future.SetValue(null);

            return builder.ConductContent(future, conductor);
        }
开发者ID:mmarkovic,项目名称:StockTicker,代码行数:7,代码来源:ManageStocksExtensions.cs

示例11: Should_downconvert_a_request_message_of_type_to_a_request_message

 public void Should_downconvert_a_request_message_of_type_to_a_request_message()
 {
     var received = new Future<Request<Simple>>();
     HeaderTypeAdapter<Request<Simple>>.TryConvert(new RequestImpl<Simple>(null, new SimpleImpl()), received.Complete).ShouldBeTrue();
     received.IsCompleted.ShouldBeTrue();
     received.Value.ShouldNotBeNull();
 }
开发者ID:rickj33,项目名称:Stact,代码行数:7,代码来源:HeaderAdapter_Specs.cs

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

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

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

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


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