Difference between .then() and .whenCompleted() methods when working with Futures?GWT vs Dart - what are the main differences? Is Dart a potential replacement of GWT?Completer and Future in dart?Launching multiple async futures in response to eventsDart - running a project does not load the dart file and not printing in the consoleDifference between a Future returning another Future and NotUsing Dart in Chrome extension content script does not run?Future execution leads to unhandled exceptionDart AppEngine Headers already sent when using FuturesCan I call any dart function inside aqueduct Response controller?How to Determine in Dart when a method is Overridden?

Defense against attacks using dictionaries

Are illustrations in novels frowned upon?

Why don't we use Cavea-B

IndexOptimize - Configuration

Why is 日本 read as "nihon" but not "nitsuhon"?

How to draw a square on cylinder?

Sleeping solo in a double sleeping bag

Factoring the square of this polynomial?

Is there a known non-euclidean geometry where two concentric circles of different radii can intersect? (as in the novel "The Universe Between")

LeetCode: Pascal's Triangle C#

Co-author responds to email by mistake cc'ing the EiC

Why would the US President need briefings on UFOs?

Is there such a thing as too inconvenient?

System to validate run time complexity requirements

How to compare two different formulations of a problem?

Shouldn't the "credit score" prevent Americans from going deeper and deeper into personal debt?

How to persuade recruiters to send me the Job Description?

Was Switzerland really impossible to invade during WW2?

Don't understand MOSFET as amplifier

Were there 486SX revisions without an FPU on the die?

When translating the law, who ensures that the wording does not change the meaning of the law?

Do ability scores have any effect on casting Wish spell

In an emergency, how do I find and share my position?

Fancy String Replace



Difference between .then() and .whenCompleted() methods when working with Futures?


GWT vs Dart - what are the main differences? Is Dart a potential replacement of GWT?Completer and Future in dart?Launching multiple async futures in response to eventsDart - running a project does not load the dart file and not printing in the consoleDifference between a Future returning another Future and NotUsing Dart in Chrome extension content script does not run?Future execution leads to unhandled exceptionDart AppEngine Headers already sent when using FuturesCan I call any dart function inside aqueduct Response controller?How to Determine in Dart when a method is Overridden?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I'm exploring Futures in Dart, and I'm confused about these two methods that Future offers. Whats the main difference between them?



Lets say I want to read a .txt using .readAsString(), I would do it like this:



void main()
File file = new File('text.txt');
Future content = file.readAsString();
content.then((data)
print(content);
);



So .then() is like a callback that fires a function once Future is completed.



But I see there is also .whenComplete() that can also fire an function once Future completes. Something like this :



void main()
File file = new File('text.txt');
Future content = file.readAsString();
content.whenComplete(()
print("Completed");
);



Difference I see here is that .then() has access to data that was returned!
What is .whenCompleted() used for? When to chose one over the other?



And also on these two links, .then() and .whenCompleted() at the end of a page there are implementations:



.then():



Future<R> then<R>(FutureOr<R> onValue(T value), Function onError);


.whenCompleted():



Future<T> whenComplete(FutureOr action());


What does Future<R> means? Or Future<T>? I get that Future is a type, but what are R and T?



Thanks!










share|improve this question






























    2















    I'm exploring Futures in Dart, and I'm confused about these two methods that Future offers. Whats the main difference between them?



    Lets say I want to read a .txt using .readAsString(), I would do it like this:



    void main()
    File file = new File('text.txt');
    Future content = file.readAsString();
    content.then((data)
    print(content);
    );



    So .then() is like a callback that fires a function once Future is completed.



    But I see there is also .whenComplete() that can also fire an function once Future completes. Something like this :



    void main()
    File file = new File('text.txt');
    Future content = file.readAsString();
    content.whenComplete(()
    print("Completed");
    );



    Difference I see here is that .then() has access to data that was returned!
    What is .whenCompleted() used for? When to chose one over the other?



    And also on these two links, .then() and .whenCompleted() at the end of a page there are implementations:



    .then():



    Future<R> then<R>(FutureOr<R> onValue(T value), Function onError);


    .whenCompleted():



    Future<T> whenComplete(FutureOr action());


    What does Future<R> means? Or Future<T>? I get that Future is a type, but what are R and T?



    Thanks!










    share|improve this question


























      2












      2








      2








      I'm exploring Futures in Dart, and I'm confused about these two methods that Future offers. Whats the main difference between them?



      Lets say I want to read a .txt using .readAsString(), I would do it like this:



      void main()
      File file = new File('text.txt');
      Future content = file.readAsString();
      content.then((data)
      print(content);
      );



      So .then() is like a callback that fires a function once Future is completed.



      But I see there is also .whenComplete() that can also fire an function once Future completes. Something like this :



      void main()
      File file = new File('text.txt');
      Future content = file.readAsString();
      content.whenComplete(()
      print("Completed");
      );



      Difference I see here is that .then() has access to data that was returned!
      What is .whenCompleted() used for? When to chose one over the other?



      And also on these two links, .then() and .whenCompleted() at the end of a page there are implementations:



      .then():



      Future<R> then<R>(FutureOr<R> onValue(T value), Function onError);


      .whenCompleted():



      Future<T> whenComplete(FutureOr action());


      What does Future<R> means? Or Future<T>? I get that Future is a type, but what are R and T?



      Thanks!










      share|improve this question














      I'm exploring Futures in Dart, and I'm confused about these two methods that Future offers. Whats the main difference between them?



      Lets say I want to read a .txt using .readAsString(), I would do it like this:



      void main()
      File file = new File('text.txt');
      Future content = file.readAsString();
      content.then((data)
      print(content);
      );



      So .then() is like a callback that fires a function once Future is completed.



      But I see there is also .whenComplete() that can also fire an function once Future completes. Something like this :



      void main()
      File file = new File('text.txt');
      Future content = file.readAsString();
      content.whenComplete(()
      print("Completed");
      );



      Difference I see here is that .then() has access to data that was returned!
      What is .whenCompleted() used for? When to chose one over the other?



      And also on these two links, .then() and .whenCompleted() at the end of a page there are implementations:



      .then():



      Future<R> then<R>(FutureOr<R> onValue(T value), Function onError);


      .whenCompleted():



      Future<T> whenComplete(FutureOr action());


      What does Future<R> means? Or Future<T>? I get that Future is a type, but what are R and T?



      Thanks!







      dart






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 15:43









      MatijaMatija

      1,0065 silver badges12 bronze badges




      1,0065 silver badges12 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          6













          .whenComplete will fire a function either when the Future completes with an error or not, instead .then will fire a function after the Future completes without an error.



          Quote from the .whenComplete API DOC




          This is the asynchronous equivalent of a "finally" block.







          share|improve this answer

























          • Thanks Mattia, and what type is <R> and <T>?

            – Matija
            Mar 27 at 17:50






          • 1





            They are not actual types, but generics.

            – Mattia
            Mar 27 at 18:05












          • Thank you, this helped me a lot!

            – Matija
            Mar 27 at 18:58










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55381236%2fdifference-between-then-and-whencompleted-methods-when-working-with-future%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          6













          .whenComplete will fire a function either when the Future completes with an error or not, instead .then will fire a function after the Future completes without an error.



          Quote from the .whenComplete API DOC




          This is the asynchronous equivalent of a "finally" block.







          share|improve this answer

























          • Thanks Mattia, and what type is <R> and <T>?

            – Matija
            Mar 27 at 17:50






          • 1





            They are not actual types, but generics.

            – Mattia
            Mar 27 at 18:05












          • Thank you, this helped me a lot!

            – Matija
            Mar 27 at 18:58















          6













          .whenComplete will fire a function either when the Future completes with an error or not, instead .then will fire a function after the Future completes without an error.



          Quote from the .whenComplete API DOC




          This is the asynchronous equivalent of a "finally" block.







          share|improve this answer

























          • Thanks Mattia, and what type is <R> and <T>?

            – Matija
            Mar 27 at 17:50






          • 1





            They are not actual types, but generics.

            – Mattia
            Mar 27 at 18:05












          • Thank you, this helped me a lot!

            – Matija
            Mar 27 at 18:58













          6












          6








          6







          .whenComplete will fire a function either when the Future completes with an error or not, instead .then will fire a function after the Future completes without an error.



          Quote from the .whenComplete API DOC




          This is the asynchronous equivalent of a "finally" block.







          share|improve this answer













          .whenComplete will fire a function either when the Future completes with an error or not, instead .then will fire a function after the Future completes without an error.



          Quote from the .whenComplete API DOC




          This is the asynchronous equivalent of a "finally" block.








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 27 at 16:40









          MattiaMattia

          9641 gold badge6 silver badges17 bronze badges




          9641 gold badge6 silver badges17 bronze badges















          • Thanks Mattia, and what type is <R> and <T>?

            – Matija
            Mar 27 at 17:50






          • 1





            They are not actual types, but generics.

            – Mattia
            Mar 27 at 18:05












          • Thank you, this helped me a lot!

            – Matija
            Mar 27 at 18:58

















          • Thanks Mattia, and what type is <R> and <T>?

            – Matija
            Mar 27 at 17:50






          • 1





            They are not actual types, but generics.

            – Mattia
            Mar 27 at 18:05












          • Thank you, this helped me a lot!

            – Matija
            Mar 27 at 18:58
















          Thanks Mattia, and what type is <R> and <T>?

          – Matija
          Mar 27 at 17:50





          Thanks Mattia, and what type is <R> and <T>?

          – Matija
          Mar 27 at 17:50




          1




          1





          They are not actual types, but generics.

          – Mattia
          Mar 27 at 18:05






          They are not actual types, but generics.

          – Mattia
          Mar 27 at 18:05














          Thank you, this helped me a lot!

          – Matija
          Mar 27 at 18:58





          Thank you, this helped me a lot!

          – Matija
          Mar 27 at 18:58








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55381236%2fdifference-between-then-and-whencompleted-methods-when-working-with-future%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현