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