本文整理汇总了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);
}
示例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();
});
});
}
示例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();
});
});
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
});
}
示例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();
});
});
}
示例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);
}
示例11: CanHandleDoneOnResolved
public void CanHandleDoneOnResolved()
{
var promise = new Promise();
var callback = 0;
promise.Done(() => ++callback);
promise.Resolve();
Assert.AreEqual(1, callback);
}
示例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);
}