I am struggling to write an F# code that would sequentially await for some asynchronous method calls. I am familiar with F# async workflows but can't figure out how to map to it a simple case.
Let's take as an example an async XmlReader. Here's how the C# code might look:
using (XmlReader r = XmlReader.Create(new StringReader(input), new XmlReaderSettings() { Async = true }))
{
while (await r.ReadAsync())
{
switch (r.NodeType)
{
case XmlNodeType.Element:
Console.WriteLine(r.LocalName);
break;
case XmlNodeType.Text:
Console.WriteLine(await r.GetValueAsync());
break;
}
}
}
If this code didn't use async calls, we could just rewrite it in F# using recursion and pattern matching. But it uses ReadAsync and GetValueAsync, how they can be expressed in F# counterpart?