Little Monkey
Little Monkey

Reputation: 6157

await, how it works?

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

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

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

Related Questions