當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。