Alternatively, until futures are a thing, you can call `beginAsync` twice to
start to async tasks:
func process() -> Void {
beginAsync {
let dataResource = await loadWebResource("bigData.txt")
//....
}
print("BigData Scheduled to load")
beginAsync {
let dataResource = await loadWebResource("smallData.txt")
//....
}
}
Futures have a number of advantages. For instance, you can use a nullable
Future to keep track of whether the task has been started at all.
Félix
> Le 21 août 2017 à 13:32, Brent Royal-Gordon via swift-evolution
> <[email protected]> a écrit :
>
>> On Aug 21, 2017, at 12:41 PM, Wallacy via swift-evolution
>> <[email protected] <mailto:[email protected]>> wrote:
>>
>> Based on these same concerns, how to do this using async/await ?
>>
>> func process() -> Void) {
>> loadWebResource("bigData.txt") { dataResource in
>> //....
>> }
>> printf("BigData Scheduled to load")
>> loadWebResource("smallData.txt") { dataResource in
>> //....
>> }
>> printf("SmallData Scheduled to load")
>>
>> }
>
>
> You would use something like the `Future` type mentioned in the proposal:
>
> func process() {
> let bigDataFuture = Future { await
> loadWebResource("bigData.txt") }
> print("BigData scheduled to load")
>
> let smallDataFuture = Future { await
> loadWebResource("smallData.txt") }
> print("SmallData scheduled to load")
>
> let bigDataResource = await bigDataFuture.get()
> let smallDataResource = await smallDataFuture.get()
> // or whatever; you could probably chain off the futures to
> handle whichever happens first first.
> ...
> }
>
> --
> Brent Royal-Gordon
> Architechies
>
> _______________________________________________
> swift-evolution mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution