Async/Await in Dart - based on futures.
Nice quick videos.
The key really in the Dart model is how it's all built on Isolates (Actors): Isolates and Event Loops - Flutter in Focus - YouTube
Nice short clip on it from the same series
hi, i've created a diagram that outlines different approaches to concurrency. the sample downloads some json, parses an image url out of it, downloads that image and draws it. please comment if i missed anything:
sorry for the small font, i wanted to fit the code fragments horizontally, this way it is easier to compare corresponding lines.
ps. a few corrections to original image are made.
pps. now i see why rust decided to go with trailing style ".await"
Couldn't the last column's "chaining style" look like this?
async func fooAsync(url: URL) {
view.image = await url
.loadDataAsync
.toValue
.some.url
.loadDataAsync
.toImage
}
As I understand it, a single await
covers all the async calls in the chain.
possibly it could if it is semantically equivalent... although the code above has to wait twice, as the
.toValue
.some.url
section in the middle of above code works on real (non async) values. so these lines can't be executed without waiting for the result of the first url loading. and then there is the second url loading, so having two awaits makes sense to me as it more closely reflects what's happening.
(there was an error on the diagram - no await() needed after toImage, as that's already a real value.)