Skip to content

Instantly share code, notes, and snippets.

@davidkellis
Last active February 13, 2018 23:12
Show Gist options
  • Save davidkellis/0ceb684c48d3bb38a802ad8cfceb1ae0 to your computer and use it in GitHub Desktop.
Save davidkellis/0ceb684c48d3bb38a802ad8cfceb1ae0 to your computer and use it in GitHub Desktop.
C# program:
using System;
using System.Threading.Tasks;
namespace Scratch
{
class Program
{
static void Main()
{
var message = GetName("John", TimeSpan.FromSeconds(5))
.ContinueWith(task => $"Hello, {task.Result}!");
Console.WriteLine(message.Result);
}
static async Task<string> GetName(string defaultValue, TimeSpan timeout)
{
return await await Task.WhenAny(
Task.Delay(timeout).ContinueWith(_ => defaultValue),
Task.Run(() => Console.ReadLine())
);
}
}
}
translated to Able:
import time.*
fn main() {
puts(get_name("John", Seconds(5)))
}
fn get_name(default_value: String, timeout: Interval) -> String {
timeout_value = Future { sleep(timeout) ; default_value }
user_input_value = Future { stdin.gets() }
future.first(timeout_value, user_input_value).value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment