Reputation: 6157
if I have something like:
var x = await retrieveData()
if (x!= nil){
do stuff
}
where retrieveData()
does an http request.
The question is: Does the if condition wait for the retrieving data or not? (In a better way, does the if condition always return false or not?)
Upvotes: 1
Views: 69
Reputation: 657148
Yes, the if condition "waits".
The code only continues to execute after the Future returned from retrieveData
completed.
Without async
/await
it would be
return retrieveData().then((x) {
if(x!= null) {
do stuff
}
})
Upvotes: 4