Skip to content

Instantly share code, notes, and snippets.

@isaacabraham
Last active November 3, 2020 17:35
Show Gist options
  • Save isaacabraham/76b675a39829c2f483214176be2f3286 to your computer and use it in GitHub Desktop.
Save isaacabraham/76b675a39829c2f483214176be2f3286 to your computer and use it in GitHub Desktop.
using System;
using System.Threading.Tasks;
namespace ConsoleApp8
{
class Program
{
static async Task<int> DoStuff()
{
var x = await System.IO.File.ReadAllTextAsync("Foo");
var y = await System.IO.File.ReadAllTextAsync("Bar");
return x.Length + y.Length;
}
static void Main(string[] args)
{
var lengths = DoStuff().Result;
Console.WriteLine($"Hello World! {lengths}");
}
}
}
let doStuff = async {
let! x = System.IO.File.ReadAllTextAsync "Foo" |> Async.AwaitTask
let! y = System.IO.File.ReadAllTextAsync "Bar" |> Async.AwaitTask
return x.Length + y.Length
}
let main args =
let lengths = doStuff |> Async.RunSynchronously
printf "Hello World! %d" lengths
open FSharp.Control.Tasks.V2
let doStuff () = task {
let! x = System.IO.File.ReadAllTextAsync "Foo"
let! y = System.IO.File.ReadAllTextAsync "Bar"
return x.Length + y.Length
}
let main args =
let lengths = doStuff().Result
printf "Hello World! %d" lengths
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment