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


C# Promise.Then方法代码示例

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


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

示例1: _if_onRejected_is_not_a_function_it_must_be_ignored_1

            public void _if_onRejected_is_not_a_function_it_must_be_ignored_1()
            {
                var promise = new Promise<object>();

                var resultPromise = promise
                    .Then(
                        v => Promise.Resolved(),
                        null
                    );

                var resolved = 0;
                var errors = 0;
                var e = new Exception();
                resultPromise.Then(() => ++resolved);
                resultPromise.Catch(ex =>
                {
                    Assert.Equal(e, ex);
                    ++errors;
                });

                promise.Reject(e);

                Assert.Equal(0, resolved);
                Assert.Equal(1, errors);
            }
开发者ID:avenema,项目名称:C-Sharp-Promise,代码行数:25,代码来源:2.2.cs

示例2: CanResolvePromiseAndTriggerThenHandler

        public void CanResolvePromiseAndTriggerThenHandler()
        {
            var promise = new Promise();
            var completed = 0;

            promise.Then(() => ++completed);
            promise.Resolve();

            Assert.AreEqual(1, completed);
        }
开发者ID:rob-blackbourn,项目名称:JetBlack.Promises,代码行数:10,代码来源:PromiseNonGenericFixture.cs

示例3: can_resolve_promise_and_trigger_then_handler

        public void can_resolve_promise_and_trigger_then_handler()
        {
            var promise = new Promise();

            var completed = 0;

            promise.Then(() => ++completed);

            promise.Resolve();

            Assert.Equal(1, completed);
        }
开发者ID:avenema,项目名称:C-Sharp-Promise,代码行数:12,代码来源:Promise_NonGeneric_Tests.cs

示例4: can_resolve_simple_promise

		public void can_resolve_simple_promise() {
			var promisedValue = 5;
			var promise = new Promise<int>(promisedValue);

			var completed = 0;
			promise.Then(v => {
				Assert.Equal(promisedValue, v);
				++completed;
			});

			Assert.Equal(1, completed);
		}
开发者ID:zon,项目名称:cardinal,代码行数:12,代码来源:PromiseTests.cs

示例5: can_resolve_promise_and_trigger_then_handler

		public void can_resolve_promise_and_trigger_then_handler() {
			var promise = new Promise<int>();

			var completed = 0;
			var promisedValue = 15;

			promise.Then(v => {
				Assert.Equal(promisedValue, v);
				++completed;
			});

			promise.Resolve(promisedValue);

			Assert.Equal(1, completed);
		}
开发者ID:zon,项目名称:cardinal,代码行数:15,代码来源:PromiseTests.cs

示例6: can_chain_promise

        public void can_chain_promise()
        {
            var promise = new Promise();
            var chainedPromise = new Promise();

            var completed = 0;

            promise
                .Then(() => chainedPromise)
                .Then(() => ++completed);

            promise.Resolve();
            chainedPromise.Resolve();

            Assert.Equal(1, completed);
        }
开发者ID:Renanse,项目名称:C-Sharp-Promise,代码行数:16,代码来源:Promise_NonGeneric_Tests.cs

示例7: PromisesShouldWorkProperly

 public void PromisesShouldWorkProperly()
 {
     // 1) Tests that multiple Then and a Done block are called as expected.
     Promise<bool> p1 = new Promise<bool>();
     CountedPromise<bool> cp = new CountedPromise<bool>(3);
     p1.Then(value => {
         cp.Resolve(value);
     })
     .Then(value => {
         cp.Resolve(value);
     })
     .Done(value => {
         cp.Resolve(value);
     });
     p1.Resolve(true);
     cp.WhenCompleted.ExpectSuccess(success => PromisesShouldWorkProperlyPart2());
 }
开发者ID:StudioJD,项目名称:unity-sdk,代码行数:17,代码来源:CloudTests.cs

示例8: _must_have_a_value_which_must_not_change

            public void _must_have_a_value_which_must_not_change()
            {
                var promisedValue = new object();
                var fulfilledPromise = new Promise<object>();
                var handled = 0;

                fulfilledPromise.Then(v =>
                {
                    Assert.Equal(promisedValue, v);
                    ++handled;
                });

                fulfilledPromise.Resolve(promisedValue);

                Assert.Throws<ApplicationException>(() => fulfilledPromise.Resolve(new object()));

                Assert.Equal(1, handled);
            }
开发者ID:avenema,项目名称:C-Sharp-Promise,代码行数:18,代码来源:2.1.cs

示例9: _if_onFulfilled_is_not_a_function_it_must_be_ignored_2

            public void _if_onFulfilled_is_not_a_function_it_must_be_ignored_2()
            {
                var promise = new Promise<object>();

                var resultPromise = promise
                    .Then(
                        (Func<object, IPromise>)null,
                        ex => { }
                    );

                var resolves = 0;
                var errors = 0;
                resultPromise.Then(() => ++resolves);
                resultPromise.Catch(ex => ++errors);

                promise.Resolve(new object());

                Assert.Equal(1, resolves);
                Assert.Equal(0, errors);
            }
开发者ID:avenema,项目名称:C-Sharp-Promise,代码行数:20,代码来源:2.2.cs

示例10: can_chain_promise_and_convert_to_non_value_promise

        public void can_chain_promise_and_convert_to_non_value_promise()
        {
            var promise = new Promise<int>();
            var chainedPromise = new Promise();

            var promisedValue = 15;
            var completed = 0;

            promise
                .Then(v => chainedPromise)
                .Then(() =>
                {
                    ++completed;
                });

            promise.Resolve(promisedValue);
            chainedPromise.Resolve();

            Assert.Equal(1, completed);
        }
开发者ID:Renanse,项目名称:C-Sharp-Promise,代码行数:20,代码来源:PromiseTests.cs

示例11: can_chain_promise_and_convert_to_promise_that_yields_a_value

        public void can_chain_promise_and_convert_to_promise_that_yields_a_value()
        {
            var promise = new Promise();
            var chainedPromise = new Promise<string>();
            var chainedPromiseValue = "some-value";

            var completed = 0;

            promise
                .Then(() => chainedPromise)
                .Then(v =>
                {
                    Assert.Equal(chainedPromiseValue, v);

                    ++completed;
                });

            promise.Resolve();
            chainedPromise.Resolve(chainedPromiseValue);

            Assert.Equal(1, completed);
        }
开发者ID:Renanse,项目名称:C-Sharp-Promise,代码行数:22,代码来源:Promise_NonGeneric_Tests.cs

示例12: can_chain_promise_and_convert_type_of_value

        public void can_chain_promise_and_convert_type_of_value()
        {
            var promise = new Promise<int>();
            var chainedPromise = new Promise<string>();

            var promisedValue = 15;
            var chainedPromiseValue = "blah";
            var completed = 0;

            promise
                .Then(v => chainedPromise)
                .Then(v =>
                {
                    Assert.Equal(chainedPromiseValue, v);

                    ++completed;
                });

            promise.Resolve(promisedValue);
            chainedPromise.Resolve(chainedPromiseValue);

            Assert.Equal(1, completed);
        }
开发者ID:Renanse,项目名称:C-Sharp-Promise,代码行数:23,代码来源:PromiseTests.cs

示例13: CanChainPromiseAndConvertToNonValuePromise

        public void CanChainPromiseAndConvertToNonValuePromise()
        {
            var promise = new Promise<int>();
            var chainedPromise = new Promise();

            const int promisedValue = 15;
            var completed = 0;

            promise
                .Then(v => chainedPromise)
                .Then(() =>
                {
                    ++completed;
                });

            promise.Resolve(promisedValue);
            chainedPromise.Resolve();

            Assert.AreEqual(1, completed);
        }
开发者ID:rob-blackbourn,项目名称:JetBlack.Promises,代码行数:20,代码来源:PromiseFixture.cs

示例14: CanChainPromiseAndConvertTypeOfValue

        public void CanChainPromiseAndConvertTypeOfValue()
        {
            var promise = new Promise<int>();
            var chainedPromise = new Promise<string>();

            const int promisedValue = 15;
            const string chainedPromiseValue = "blah";
            var completed = 0;

            promise
                .Then(v => chainedPromise)
                .Then(v =>
                {
                    Assert.AreEqual(chainedPromiseValue, v);
                    ++completed;
                });

            promise.Resolve(promisedValue);
            chainedPromise.Resolve(chainedPromiseValue);

            Assert.AreEqual(1, completed);
        }
开发者ID:rob-blackbourn,项目名称:JetBlack.Promises,代码行数:22,代码来源:PromiseFixture.cs

示例15: ThenHandlerIsNotInvokedForRejectedPromise

        public void ThenHandlerIsNotInvokedForRejectedPromise()
        {
            var promise = new Promise<int>();

            promise.Then(v =>
            {
                throw new ApplicationException("This shouldn't happen");
            });

            promise.Reject(new ApplicationException("Rejection!"));
        }
开发者ID:rob-blackbourn,项目名称:JetBlack.Promises,代码行数:11,代码来源:PromiseFixture.cs


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