Futures
and await;
there are two key tools we use for this.waitFor
and streams
.waitFor
is a fairly new Dart function which ONLY works for Dart CLI applications and can be found in the dart:cli
package.waitFor
allows a Dart CLI application to turn what would normally be an async method (returning a future) into a normal synchronous method by effectively 'absorbing' a future. Normally in Dart, as soon as you have one async function, its async all of the way up.waitFor.
waitFor
does however have a problem. If an exception gets thrown whilst in a waitFor
call, then the stacktrace generated will be a microtask based stack trace. These stacktraces are useless as they don't show you where the original call came from.waitForEx
was born. waitForEx
is my own little creation that does three things.waitFor
and catches any exceptions