本文整理汇总了C#中Promise.FlatMap方法的典型用法代码示例。如果您正苦于以下问题:C# Promise.FlatMap方法的具体用法?C# Promise.FlatMap怎么用?C# Promise.FlatMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Promise
的用法示例。
在下文中一共展示了Promise.FlatMap方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestFailure
public void TestFailure()
{
Promise<long> p = new Promise<long>(cb => cb("uh oh", default(long)));
bool test = false;
p.Success(x => test = true);
Assert.IsFalse(test);
p.Fail(s => test = true);
Assert.IsTrue(test);
var p2 = p.FlatMap(l => new Promise<int>(cb => cb(null, 3)));
test = false;
p2.Success(x => test = true);
Assert.IsFalse(test);
p2.Fail(s => test = true);
Assert.IsTrue(test);
}
示例2: TestcompoundFunc
public void TestcompoundFunc()
{
Promise<string> suf = new Promise<string>(cb => cb(null, "second"));
Promise<string> full = suf.FlatMap(x => convert("first", x));
full.Success(x => Assert.AreEqual(x, "first, second"));
bool test = false;
full.Success(x => test = true);
Assert.IsTrue(test);
}
示例3: TestFlatMap
public void TestFlatMap()
{
Promise<int> p1 = new Promise<int>(cb => cb(null, 5));
Promise<string> p2 = p1.FlatMap(i => new Promise<string>(cb => cb(null, i.ToString())));
p2.Success(s => Assert.AreEqual(s, "5"));
bool test = false;
p2.Success(x => test = true);
Assert.IsTrue(test);
}