Last active
February 13, 2018 23:12
-
-
Save davidkellis/0ceb684c48d3bb38a802ad8cfceb1ae0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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