Book Image

DART Cookbook

By : Ivo Balbaert
Book Image

DART Cookbook

By: Ivo Balbaert

Overview of this book

Table of Contents (18 chapters)
Dart Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Introduction


The Future class from dart:async lies in the basis of all asynchronous programming in Dart. A Future is, in fact, a computation that is deferred; it represents an object whose value will be available sometime in the future. It is not available immediately, because the function that returns its value depends on some kind of input/output and is, thus, unpredictable by nature. Here are some examples: a time-consuming computation, reading in a big dataset, and searching through a number of websites.

In the two previous chapters, quite a lot of recipes used Futures; in Chapter 6, Working with Files and Streams, we had the following recipes using Futures:

  • Reading and processing a file line by line

  • Concatenating files the asynchronous way

  • Downloading a file

In the preceding chapter, we used Futures in the following recipes:

  • Making a web server

  • Receiving data on the web server

  • Using sockets

In this chapter, we will concentrate on how to write elegant code for Futures and combine...