Await example shown here http://docs.elementscompiler.com/Silver/LanguageExtensions/Await/
does not work.
Await example shown here http://docs.elementscompiler.com/Silver/LanguageExtensions/Await/
does not work.
Thanx. there seem to be two bugs. For one, the “trailing closure” syntax doesn’t seem to work in this scenario, wile this code compiles ok:
let task = Task<String>({
Thread.Sleep(10000)
return "Result!"
})
For another, the actual __await
call does not compile as expected either, i’ll have that looked at.
i logged two issues.
thanx!
Update: the _await
call actually works fine, as long as you make sure to target .NET 4.5 or later. I’ll make sure we improve the error message for this. The trailing closure issue we will need to fix. This code should work:
import System.Collections.Generic
import System.Linq
import System.Text
import System.Threading
import System.Threading.Tasks
println("The magic happens here.")
func test() -> Task<String> {
let task = Task<String>({
Thread.Sleep(10000)
return "Result!"
})
task.Start()
return task
}
func OtherMethod() {
println(__await test())
println("after test")
}
If you pass more than one parameter to test then it doesn’t work. Following doesn’t compile and raise error
“Error 1 (E316) No overloaded method “test” with these parameters on type Window1!”
func test(a: String, b: String) -> Task<String> {
let task = Task<String>({
Thread.Sleep(10000)
return "Result!"
})
task.Start()
return task
}
It works if the call to async method includes name of second parameter like
test("s", b: "c")
Right, thats how your test function is defined. By default, all but the first parameter of Swift functions are named, and their names need to be specified when calling. if you don’t want that, you need to define test()
as
func test(a: String, _ b: String) -> Task<String> {
Thanks, my lack of Swift knowledge.