本文整理匯總了C#中Promise.Transform方法的典型用法代碼示例。如果您正苦於以下問題:C# Promise.Transform方法的具體用法?C# Promise.Transform怎麽用?C# Promise.Transform使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Promise
的用法示例。
在下文中一共展示了Promise.Transform方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: _when_promise1_is_resolved
public void _when_promise1_is_resolved()
{
var promise1 = new Promise<object>();
var promisedValue1 = new object();
var promisedValue2 = new object();
var promise2 =
promise1.Transform(_ => promisedValue2);
var promise1ThenHandler = 0;
promise1.Then(v =>
{
Assert.Equal(promisedValue1, v);
++promise1ThenHandler;
});
var promise2ThenHandler = 0;
promise2.Then(v =>
{
Assert.Equal(promisedValue2, v);
++promise2ThenHandler;
});
promise1.Resolve(promisedValue1);
Assert.Equal(1, promise1ThenHandler);
Assert.Equal(1, promise2ThenHandler);
}
示例2: 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
.Transform<string>(v =>
{
throw ex;
})
.Catch(e =>
{
Assert.Equal(ex, e);
++errors;
});
promise.Resolve(promisedValue);
Assert.Equal(1, errors);
}
示例3: rejection_of_source_promise_rejects_transformed_promise
public void rejection_of_source_promise_rejects_transformed_promise()
{
var promise = new Promise<int>();
var ex = new Exception();
var errors = 0;
promise
.Transform(v => v.ToString())
.Catch(e =>
{
Assert.Equal(ex, e);
++errors;
});
promise.Reject(ex);
Assert.Equal(1, errors);
}
示例4: can_transform_promise_value
public void can_transform_promise_value()
{
var promise = new Promise<int>();
var promisedValue = 15;
var completed = 0;
promise
.Transform(v => v.ToString())
.Then(v =>
{
Assert.Equal(promisedValue.ToString(), v);
++completed;
});
promise.Resolve(promisedValue);
Assert.Equal(1, completed);
}