5
The Dart language provides several mechanisms for handling asynchronous calls. One I’m very used to is modifying await
, which can be used in functions marked as async
.
However, we are sometimes in a function that is not marked as asynchronous, and in such cases we are presented to class objects Future
. This class has some methods that I can point out as callbacks
:
then()
whenComplete()
catchError()
The context documentation that VS Code provides on the catchErro()
me is very clear (free translation):
Manipulates errors made by it
Future
But I was confused about the use of then()
and that of whenComplete()
. About then()
:
Registers callbacks to be called when this
Future
complete
And the whenComplete()
:
Records a function to be called when it
Future
complete
Then my question remains:
- what is the difference between the two methods?
- what is the classic case of
then()
? what is the classic case ofwhenComplete()
?