-
Notifications
You must be signed in to change notification settings - Fork 148
Async and Await
Boo supports the async/await
pattern as implemented in C# 5.0.
Unlike C#, Boo does not implement async
and await
as keywords; instead it uses Boo's metaprogramming facilities. A method can be marked as asynchronous by adding the [AsyncAttribute]
attribute to it, while marking a closure as async
and await
ing a method call are done with metamethod invocations. (All three of these metaprogramming features are found in Boo.Lang.Extensions
, which the compiler automatically references by default, so for all intents and purposes they can be considered built-in by Boo developers.)
Examples:
Async hello world:
import System.Threading
import System.Threading.Tasks
[async] def F(a as string) as Task:
await Task.Factory.StartNew({ System.Console.WriteLine(a) })
F('Hello, World!').Wait()
Async closure:
import System.Threading
import System.Threading.Tasks
import System
def Foo(f as Func[of Task[of int]]):
return f()
Console.WriteLine(TestCase.Foo(async({ return 14 })))
(Please note that these are examples of the syntax only, and not realistic uses of the feature.)
Credits: Both the feature implementation and the test suite were ported from Microsoft's official implementation in the Roslyn C# compiler by Mason Wheeler, with significant assistance from Microsoft's Jonathan Marolf and Neal Gafter.