當前位置: 首頁>>代碼示例>>C#>>正文


C# Promise.ThenAll方法代碼示例

本文整理匯總了C#中Promise.ThenAll方法的典型用法代碼示例。如果您正苦於以下問題:C# Promise.ThenAll方法的具體用法?C# Promise.ThenAll怎麽用?C# Promise.ThenAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Promise的用法示例。


在下文中一共展示了Promise.ThenAll方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ChainMultiplePromisesUsingAllAndConvertToNonValuePromise

        public void ChainMultiplePromisesUsingAllAndConvertToNonValuePromise()
        {
            var promise = new Promise<string>();
            var chainedPromise1 = new Promise();
            var chainedPromise2 = new Promise();

            var completed = 0;

            promise
                //.ThenAll(i => LinqExts.FromItems(chainedPromise1, chainedPromise2).Cast<IPromise>())
                .ThenAll(i => new[]{chainedPromise1, chainedPromise2})
                .Then(() =>
                {
                    ++completed;
                });

            Assert.AreEqual(0, completed);

            promise.Resolve("hello");

            Assert.AreEqual(0, completed);

            chainedPromise1.Resolve();

            Assert.AreEqual(0, completed);

            chainedPromise2.Resolve();

            Assert.AreEqual(1, completed);
        }
開發者ID:rob-blackbourn,項目名稱:JetBlack.Promises,代碼行數:30,代碼來源:PromiseFixture.cs

示例2: ChainMultiplePromisesUsingAllThatAreResolvedOutOfOrder

        public void ChainMultiplePromisesUsingAllThatAreResolvedOutOfOrder()
        {
            var promise = new Promise<string>();
            var chainedPromise1 = new Promise<int>();
            var chainedPromise2 = new Promise<int>();
            const int chainedResult1 = 10;
            const int chainedResult2 = 15;

            var completed = 0;

            promise
                //.ThenAll(i => LinqExts.FromItems(chainedPromise1, chainedPromise2).Cast<IPromise<int>>())
                .ThenAll(i => new[]{chainedPromise1, chainedPromise2})
                .Then(result =>
                {
                    var items = result.ToArray();
                    Assert.AreEqual(2, items.Length);
                    Assert.AreEqual(chainedResult1, items[0]);
                    Assert.AreEqual(chainedResult2, items[1]);

                    ++completed;
                });

            Assert.AreEqual(0, completed);

            promise.Resolve("hello");

            Assert.AreEqual(0, completed);

            chainedPromise2.Resolve(chainedResult2);

            Assert.AreEqual(0, completed);

            chainedPromise1.Resolve(chainedResult1);

            Assert.AreEqual(1, completed);
        }
開發者ID:rob-blackbourn,項目名稱:JetBlack.Promises,代碼行數:37,代碼來源:PromiseFixture.cs

示例3: chain_multiple_value_promises_using_all_resolved_out_of_order

        public void chain_multiple_value_promises_using_all_resolved_out_of_order()
        {
            var promise = new Promise();
            var chainedPromise1 = new Promise<int>();
            var chainedPromise2 = new Promise<int>();
            var chainedResult1 = 10;
            var chainedResult2 = 15;

            var completed = 0;

            promise
                .ThenAll(() => LinqExts.FromItems(chainedPromise1, chainedPromise2).Cast<IPromise<int>>())
                .Then(result =>
                {
                    var items = result.ToArray();
                    Assert.Equal(2, items.Length);
                    Assert.Equal(chainedResult1, items[0]);
                    Assert.Equal(chainedResult2, items[1]);

                    ++completed;
                });

            Assert.Equal(0, completed);

            promise.Resolve();

            Assert.Equal(0, completed);

            chainedPromise2.Resolve(chainedResult2);

            Assert.Equal(0, completed);

            chainedPromise1.Resolve(chainedResult1);

            Assert.Equal(1, completed);
        }
開發者ID:Renanse,項目名稱:C-Sharp-Promise,代碼行數:36,代碼來源:Promise_NonGeneric_Tests.cs

示例4: chain_multiple_promises_using_all

        public void chain_multiple_promises_using_all()
        {
            var promise = new Promise();
            var chainedPromise1 = new Promise();
            var chainedPromise2 = new Promise();

            var completed = 0;

            promise
                .ThenAll(() => LinqExts.FromItems(chainedPromise1, chainedPromise2).Cast<IPromise>())
                .Then(() => ++completed);

            Assert.Equal(0, completed);

            promise.Resolve();

            Assert.Equal(0, completed);

            chainedPromise1.Resolve();

            Assert.Equal(0, completed);

            chainedPromise2.Resolve();

            Assert.Equal(1, completed);
        }
開發者ID:Renanse,項目名稱:C-Sharp-Promise,代碼行數:26,代碼來源:Promise_NonGeneric_Tests.cs

示例5: ChainMultiplePromisesUsingAll

        public void ChainMultiplePromisesUsingAll()
        {
            var promise = new Promise();
            var chainedPromise1 = new Promise();
            var chainedPromise2 = new Promise();

            var completed = 0;

            promise
                //.ThenAll(() => LinqExts.FromItems(chainedPromise1, chainedPromise2).Cast<IPromise>())
                .ThenAll(() => new []{chainedPromise1, chainedPromise2})
                .Then(() => ++completed);

            Assert.AreEqual(0, completed);

            promise.Resolve();

            Assert.AreEqual(0, completed);

            chainedPromise1.Resolve();

            Assert.AreEqual(0, completed);

            chainedPromise2.Resolve();

            Assert.AreEqual(1, completed);
        }
開發者ID:rob-blackbourn,項目名稱:JetBlack.Promises,代碼行數:27,代碼來源:PromiseNonGenericFixture.cs

示例6: chain_multiple_promises_using_all_and_convert_to_non_value_promise

        public void chain_multiple_promises_using_all_and_convert_to_non_value_promise()
        {
            var promise = new Promise<string>();
            var chainedPromise1 = new Promise();
            var chainedPromise2 = new Promise();

            var completed = 0;

            promise
                .ThenAll(i => LinqExts.FromItems(chainedPromise1, chainedPromise2).Cast<IPromise>())
                .Then(() =>
                {
                    ++completed;
                });

            Assert.Equal(0, completed);

            promise.Resolve("hello");

            Assert.Equal(0, completed);

            chainedPromise1.Resolve();

            Assert.Equal(0, completed);

            chainedPromise2.Resolve();

            Assert.Equal(1, completed);
        }
開發者ID:Renanse,項目名稱:C-Sharp-Promise,代碼行數:29,代碼來源:PromiseTests.cs


注:本文中的Promise.ThenAll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。