本文整理汇总了C#中Promise.Map方法的典型用法代码示例。如果您正苦于以下问题:C# Promise.Map方法的具体用法?C# Promise.Map怎么用?C# Promise.Map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Promise
的用法示例。
在下文中一共展示了Promise.Map方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestMapPromise
public void TestMapPromise()
{
Promise<int> p1 = new Promise<int>(cb => cb(null, 5));
Promise<string> p2 = p1.Map(x => x.ToString());
p2.Success(s => Assert.AreEqual(s, "5"));
bool test = false;
p2.Success(s => test = true);
Assert.IsTrue(test);
}
示例2: rejection_of_source_promise_rejects_mapped_promise
public void rejection_of_source_promise_rejects_mapped_promise() {
var promise = new Promise<int>();
var ex = new Exception();
var errors = 0;
promise
.Map(v => v.ToString())
.Catch(e => {
Assert.Equal(ex, e);
++errors;
});
promise.Reject(ex);
Assert.Equal(1, errors);
}
示例3: exception_thrown_during_transform_rejects_transformed_promise
public void exception_thrown_during_transform_rejects_transformed_promise() {
var promise = new Promise<int>();
var promisedValue = 15;
var errors = 0;
var ex = new Exception();
promise
.Map<string>(v => {
throw ex;
})
.Catch(e => {
Assert.Equal(ex, e);
++errors;
});
promise.Resolve(promisedValue);
Assert.Equal(1, errors);
}
示例4: can_map_promise_value
public void can_map_promise_value() {
var promise = new Promise<int>();
var promisedValue = 15;
var completed = 0;
promise
.Map(v => v.ToString())
.Then(v => {
Assert.Equal(promisedValue.ToString(), v);
++completed;
});
promise.Resolve(promisedValue);
Assert.Equal(1, completed);
}