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


C# Promise.Done方法代码示例

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


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

示例1: AsyncStreamWriter

 public AsyncStreamWriter(Stream stream, Action onComplete, Action<Exception> onError)
 {
   _stream = stream;
   _promise = new Promise<bool>();
   if (onComplete != null) _promise.Done(r => onComplete());
   if (onError != null) _promise.Fail(onError);
 }
开发者ID:rneuber1,项目名称:InnovatorAdmin,代码行数:7,代码来源:AsyncStreamWriter.cs

示例2: ShouldAssociateGodfather

    public void ShouldAssociateGodfather(Cloud cloud)
    {
        Login2NewUsers(cloud, (gamer1, gamer2) => {
            // Expects godchild event
            Promise restOfTheTestCompleted = new Promise();
            gamer1.StartEventLoop();
            gamer1.Godfather.OnGotGodchild += (GotGodchildEvent e) => {
                Assert(e.Gamer.GamerId == gamer2.GamerId, "Should come from player2");
                Assert((object)e.Reward == (object)Bundle.Empty, "No reward should be associated");
                restOfTheTestCompleted.Done(CompleteTest);
            };

            // P1 generates a code and associates P2 with it
            gamer1.Godfather.GenerateCode()
            // Use code
            .ExpectSuccess(genCode => gamer2.Godfather.UseCode(genCode))
            .ExpectSuccess(dummy => gamer2.Godfather.GetGodfather())
            .ExpectSuccess(result => {
                Assert(result.GamerId == gamer1.GamerId, "P1 should be godfather");
                Assert(result.AsBundle().Root.Has("godfather"), "Underlying structure should be accessible");
                return gamer1.Godfather.GetGodchildren();
            })
            .ExpectSuccess(result => {
                Assert(result.Count == 1, "Should have only one godchildren");
                Assert(result[0].GamerId == gamer2.GamerId, "P2 should be godchildren");
                restOfTheTestCompleted.Resolve();
            });
        });
    }
开发者ID:StudioJD,项目名称:unity-sdk,代码行数:29,代码来源:GodfatherTests.cs

示例3: ShouldAddFriend

    public void ShouldAddFriend(Cloud cloud)
    {
        // Use two test accounts
        Login2NewUsers(cloud, (gamer1, gamer2) => {
            // Expects friend status change event
            Promise restOfTheTestCompleted = new Promise();
            gamer1.StartEventLoop();
            gamer1.Community.OnFriendStatusChange += (FriendStatusChangeEvent e) => {
                Assert(e.FriendId == gamer2.GamerId, "Should come from P2");
                Assert(e.NewStatus == FriendRelationshipStatus.Add, "Should have added me");
                restOfTheTestCompleted.Done(CompleteTest);
            };

            // Add gamer1 as a friend of gamer2
            gamer2.Community.AddFriend(gamer1.GamerId)
            .ExpectSuccess(addResult => {
                // Then list the friends of gamer1, gamer2 should be in it
                return gamer1.Community.ListFriends();
            })
            .ExpectSuccess(friends => {
                Assert(friends.Count == 1, "Expects one friend");
                Assert(friends[0].GamerId == gamer2.GamerId, "Wrong friend ID");
                restOfTheTestCompleted.Resolve();
            });
        });
    }
开发者ID:StudioJD,项目名称:unity-sdk,代码行数:26,代码来源:CommunityTests.cs

示例4: can_handle_Done_onResolved

        public void can_handle_Done_onResolved()
        {
            var promise = new Promise();
            var callback = 0;

            promise.Done(() => ++callback);

            promise.Resolve();

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

示例5: can_handle_Done_onResolved_with_onReject

        public void can_handle_Done_onResolved_with_onReject()
        {
            var promise = new Promise();
            var callback = 0;
            var errorCallback = 0;

            promise.Done(
                () => ++callback,
                ex => ++errorCallback
            );

            promise.Resolve();

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

示例6: can_handle_Done_onResolved

        public void can_handle_Done_onResolved()
        {
            var promise = new Promise<int>();
            var callback = 0;
            var expectedValue = 5;

            promise.Done(value =>
            {
                Assert.Equal(expectedValue, value);

                ++callback;
            });

            promise.Resolve(expectedValue);

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

示例7: CanHandleDoneOnResolvedWithOnReject

        public void CanHandleDoneOnResolvedWithOnReject()
        {
            var promise = new Promise<int>();
            var callback = 0;
            var errorCallback = 0;
            const int expectedValue = 5;

            promise.Done(
                value =>
                {
                    Assert.AreEqual(expectedValue, value);

                    ++callback;
                },
                ex =>
                {
                    ++errorCallback;
                }
            );

            promise.Resolve(expectedValue);

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

示例8: PromisesShouldWorkProperlyPart2

    private void PromisesShouldWorkProperlyPart2()
    {
        // 2) Test that that an unhandled exception is triggered as expected
        Promise[] expectingException = new Promise[1];
        EventHandler<ExceptionEventArgs> promiseExHandler = (sender, e) => {
            expectingException[0].Resolve();
        };
        FailOnUnhandledException = false;
        Promise.UnhandledException += promiseExHandler;

        Promise<bool> prom = new Promise<bool>();
        // With just then, the handler should not be called
        expectingException[0] = new Promise().Then(() => FailTest("Should not call UnhandledException yet"));
        prom.Reject(new InvalidOperationException());

        // But after a done, it should be invoked
        Wait(100).Then(() => {
            expectingException[0] = new Promise();
            expectingException[0].Then(() => {
                Promise.UnhandledException -= promiseExHandler;
                FailOnUnhandledException = true;
                PromisesShouldWorkProperlyPart3();
            });
            prom.Done();
        });
    }
开发者ID:StudioJD,项目名称:unity-sdk,代码行数:26,代码来源:CloudTests.cs

示例9: ShouldSendEvent

 public void ShouldSendEvent(Cloud cloud)
 {
     Login2NewUsers(cloud, (gamer1, gamer2) => {
         // Wait event for P1
         Promise finishedSendEvent = new Promise();
         DomainEventLoop loop = gamer1.StartEventLoop();
         loop.ReceivedEvent += (sender, e) => {
             Assert(sender == loop, "Event should come from the loop");
             Assert(e.Message["event"]["hello"] == "world", "Message invalid");
             loop.Stop();
             // Wait the results of SendEvent as well
             finishedSendEvent.Done(CompleteTest);
         };
         // Send event as P2
         gamer2.Community.SendEvent(
             gamerId: gamer1.GamerId,
             eventData: Bundle.CreateObject("hello", "world"))
         .ExpectSuccess(result => {
             Assert(result, "Expected true result");
             finishedSendEvent.Resolve();
         });
     });
 }
开发者ID:StudioJD,项目名称:unity-sdk,代码行数:23,代码来源:CommunityTests.cs

示例10: CanHandleDoneOnResolvedWithOnReject

        public void CanHandleDoneOnResolvedWithOnReject()
        {
            var promise = new Promise();
            var callback = 0;
            var errorCallback = 0;

            promise.Done(
                () => ++callback,
                ex => ++errorCallback
            );

            promise.Resolve();

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

示例11: CanHandleDoneOnResolved

        public void CanHandleDoneOnResolved()
        {
            var promise = new Promise();
            var callback = 0;

            promise.Done(() => ++callback);

            promise.Resolve();

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

示例12: exception_during_Done_onResolved_triggers_error_hander

        public void exception_during_Done_onResolved_triggers_error_hander()
        {
            var promise = new Promise<int>();
            var callback = 0;
            var errorCallback = 0;
            var expectedValue = 5;
            var expectedException = new Exception();

            promise.Done(
                value =>
                {
                    Assert.Equal(expectedValue, value);

                    ++callback;

                    throw expectedException;
                },
                ex =>
                {
                    Assert.Equal(expectedException, ex);

                    ++errorCallback;
                }
            );

            promise.Resolve(expectedValue);

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


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