Flutter 14 - Async programming

preview_player
Показать описание
Check out my courses on Udemy

Dart Beginners

Dart Intermediate

Dart Advanced

Flutter Beginners

Flutter Intermediate

Flutter Advanced
Рекомендации по теме
Комментарии
Автор

You way to explain code and giving example for every different scenario is very good. It help us understand the concepts in deep. Big thanx to you. Loved It.

cutechamps
Автор

Great video! One thing to point out, Dart is single threaded (if not running on multiple isolates) meaning no code is ever parallel. Async or futures run in a eventloop, and async tasks can be queued very efficiently. This means more preformance (ie more work per sec) when theres is waiting that needs to be done (database, http, etc) by the CPU. But async wont help if you are blocking ie. calculating something expensive like large primes.

stuff
Автор

I couldn't figure out why the following code didn't work correctly. >> 5:27 <<

I dont get it, Its the same code.
I also tried it on DartPad. The result is the same.

my result and DartPad's result:
starting
Async 0
Async 1
Async 2
Async 3
Async 4
done

According to video, it has to be:
starting
done
Async 0
Async 1
Async 2
Async 3
Async 4

The Code:

import 'dart:async';

Future<bool> longWait(String prefix) async {
for (int i = 0; i < 5; i++) {
print('$prefix $i');
}
return true;
}

Future testAsync() async {
print('starting');
longWait('Async');
print('done');
}

main() {
testAsync();
}

mertmertoglu
Автор

Spectacular, my friend!
Quoting Elvis: "Thank you very much!" 😜

rogeriolimas
Автор

FYI, your testChain() code appears to have been broken in the transition from Dart 1 to Dart 2. The fix is to add an explicit type parameter to the function assignment on line 30. It should now read:
Future<bool> f = longWait('Chains');

I found the explanation & fix on the following page:

shadowmn
Автор

This was very helpful. thanks for posting!

pebre
Автор

Neat, extremely similar to ES async/await

yeeppers
Автор

Very much the same as Javascript promises except dart calls them futures.

devopssimon
Автор

For me the output was same as it would be if it wasn't asynchronous. Without using "await" => Starting - Async - Done.. Even tried a higher number in the for loop condition. Why the difference..? Is anything changed since then..?

akhilsoman
Автор

the examples won't work anymore in current dart/flutter version.

JoaoCSpeixoto
Автор

this is cool but I don't like Dart!! we want more QML vids!! >:)

KingHerring
visit shbcf.ru