Skip to content

Instantly share code, notes, and snippets.

@mpfaff
Created March 3, 2019 23:20
Show Gist options
  • Save mpfaff/7f018c43c5e976e37adc60d57213c6af to your computer and use it in GitHub Desktop.
Save mpfaff/7f018c43c5e976e37adc60d57213c6af to your computer and use it in GitHub Desktop.

Futures & Streams


"I find that sometimes real-world analogies work well for explaining / remembering concepts. Here's one - it's not perfect but it helps me." "Think that you are at one of those modern sushi restaurants where you have a belt going around the room with sushi boats on it. You just sit down and wait till one goes by, grab it and eat. But they also allow you to order carry out." — Nitya Narasimhan, 2018/06/17

Future

"A Future represents a computation that doesn’t complete immediately. Where a normal function returns the result, an asynchronous function returns a Future, which will eventually contain the result. The future will tell you when the result is ready." — Dart documentation

"A Future is like the token with a number on it that they give you when you order takeout; you made the request, but the result is not yet ready but you have a placeholder. And when the result is ready, you get a callback (the digital board above the takeout counter shows your number or they shout it out) - you can now go in and grab your food (the result) to take out." — Nitya Narasimhan, 2018/06/17


Stream

"A stream is a sequence of asynchronous events. It is like an asynchronous Iterable where, instead of getting the next event when you ask for it, the stream tells you that there is an event when it is ready." — Dart documentation

"A Stream is like that belt carrying little sushi bowls. By sitting down at that table, you've "subscribed" to the stream. You don't know when the next sushi boat will arrive - but when the chef (message source) places it in the stream (belt), then the subscribers will receive it. The important thing to note is that they arrive asynchronously (you have no idea when the next boat/message will come) but they will arrive in sequence (i.e., if the chef puts three types of sushi on the belt, in some order -- you will see them come by you in that same order)" — Nitya Narasimhan, 2018/06/17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment