Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Remember that you can chain futures, which will reduce your indentation by quite a bit.</p> <p>The downside is that you don't get nested scopes, which can be useful if you have more than one value to propagate between async blocks, but that can be worked around in a few ways.</p> <p>Here's you example 3 with chaining:</p> <pre class="lang-dart prettyprint-override"><code>// Example 3 with chaining void main() { String checkPoint = "Get User Input"; getUserInput().then((input) { int maxIters = int.parse(input[4]); bool clearTable = (input[5] == "y"); int div = initialize(maxIters); shouldPrint = false; // printing off String uri = "postgres://${input[1]}:${input[2]}@localhost:5432/${input[3]}"; checkPoint = "Connect to Database"; return connectToDb(uri, input[7]).then((bool connected) { if (db == null) fatal(checkPoint, "Unable to conenct to Db"); print ("Processing database ......"); checkPoint = "Clear Table"; return clearTable(shouldClearTable); }).then((result) { print (result+"\n"); checkPoint = "Process Inserts"; return processInserts(maxIters, div); }).then((result) { print(''); checkPoint = "Set-up Random Keys"; return setupRandKeys(); }).then((result) { print(''); checkPoint = "Process Updates"; return processUpdates(maxIters, div); }).then((result) { String totValue = formatAmount(grandTotAmt, true, 2); print("Grand Total added to database = \$${totValue}"); return db.close(); // exit(0); pretty much never call exit() }); }).catchError((error) =&gt; fatal(checkPoint, error)); } </code></pre> <p>Edit: Oops, looking more closely I got bit by the scoping problem... I added a level of nesting just to capture the needed vars in a scope accessible by the following blocks. I'm also removing the hungarian-ish notation, because... don't do that in Dart :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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