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