本文整理匯總了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);
}