Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Asynchronous programming in Dart

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

Asynchronous programming in Dart

Avatar for Danvick Miller

Danvick Miller

March 26, 2021
Tweet

More Decks by Danvick Miller

Other Decks in Programming

Transcript

  1. CONTENTS C O N T E N T S Isolates

    and Event Loop 1 Futures 2 Async / Await 3 Streams 4
  2. An event loop’s job is to take an item from

    the event queue and handle it, repeating these two steps for as long as the queue has items.
  3. Future - a promise that you'll get some value or

    accomplish a task in future Completes with a value or may return an error States: Uncompleted, Success, Error
  4. • then() - executed when the Future completes with a

    value • catchError() - executed when the Future completes with an error • whenComplete() - executed when the Future completes; whether with an error or value
  5. Streams - a source of asynchronous events (elements) delivered sequentially

    Used to get asynchronous sequence of data like from APIs, reading from files. Once all data elements have been emitted, a special event signalling the stream is done will notify any listeners that there is no more.
  6. Single-subscription streams - only one listener at a time Broadcast

    streams - Multiple listeners at a time *Without subscribing/listening, to a stream, it's just an object with potential values
  7. async/await keywords - syntactic sugar to make it easy to

    use Futures and Streams Just alternative syntax for handling Futures and Streams Your code ends up looking like syncronous code