Note that there are some explanatory texts on larger screens.

plurals
  1. POHow return Future from Future? Or this is prohibited in async library?
    text
    copied!<p>How I can return Future value from Future object? This code does not work.</p> <pre class="lang-dart prettyprint-override"><code>import 'dart:async'; void main() { var temp = foo(); temp.then((Future&lt;int&gt; future) { future.then((int result) { print(result); }); }); } Future&lt;Future&lt;int&gt;&gt; foo() { return new Future&lt;Future&lt;int&gt;&gt;(() { return new Future&lt;int&gt;(() =&gt; 5); }); } </code></pre> <p>How to prevent unnecessary unwrapping?</p> <p>In this case in async library 'Future' declared as generic class.</p> <pre class="lang-dart prettyprint-override"><code>abstract class Future&lt;T&gt; { } </code></pre> <p>If I create expression as the following</p> <pre class="lang-dart prettyprint-override"><code>new Future&lt;Future&lt;int&gt;&gt;(); </code></pre> <p>Then with type <code>T</code> specified as <code>Future&lt;int&gt;</code> which result expected from generic class Future?</p> <p>I thing that result must be as specified in type argument <code>T</code>.</p> <p>I.e. <code>Future&lt;int&gt;.</code></p> <p>But result is not as expected. There is no information found about this abnormal behavior on Dart API site.</p> <p>If this is a "feature" (but I think that abnormal behavior wrongly to call "feature') then why it not documented in Dart API?</p> <p>How can be explained this discrepancy?</p> <p>Why this code not generated errors and warnings?</p> <p>Another IDENTICAL example but w/o using Future.</p> <pre class="lang-dart prettyprint-override"><code>void main() { var temp = foo(); temp.baz((Foo&lt;int&gt; foo) { foo.baz((int result) { print(result); }); }); } Foo&lt;Foo&lt;int&gt;&gt; foo() { return new Foo&lt;Foo&lt;int&gt;&gt;(() { return new Foo&lt;int&gt;(() =&gt; 5); }); } </code></pre> <p>If in this case result will be as when using Future (i.e. unexpected) then how we can call this code? Normal or abnormal?</p> <p>Or maybe the Future in Dart some special (magic)?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload