[swift-evolution] [Concurrency] async/await + actors
Thorsten Seitz
tseitz42 at icloud.com
Mon Sep 11 12:34:21 CDT 2017
> Am 21.08.2017 um 22:32 schrieb Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org>:
>
>> On Aug 21, 2017, at 12:41 PM, Wallacy via swift-evolution <swift-evolution at swift.org> 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.
> ...
> }
Like others have already proposed I would imagine to be able to write something like this (adding a return type to do something with the data).
func process() async -> (Data, Data) {
let bigData = async loadWebResource("bigData.txt")
print("BigData scheduled to load")
let bigData = async loadWebResource("bigData.txt")
print("SmallData scheduled to load")
return await (bigData, smallData)
}
where bigData and smallData have the type `async Data` which has
to be `await`ed upon to get at the `Data`.
-Thorsten
>
> --
> Brent Royal-Gordon
> Architechies
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170911/bd4d6d9d/attachment.html>
More information about the swift-evolution
mailing list