Callback to the Future

Nino Handler
Flutter Community
3 min readJun 2, 2020

--

My name is Marty McFly, I’m a Dart developer and I just recently had a revelation moment.

It all started with me and my laptop being set back in time into the dark ages of callbacks. It was not by chance but on purpose that I had to go there. A very important piece of data I had to retrieve. Coming from the Future everything back there seemed uncomfortable and convoluted. I definitely didn’t like what I saw and what I now would call a callback hell. Despite my wish to get back, I had to ensure that I would bring this data with me. Little did I know how easy it finally would be but great was the adventure that led me there. This is the story I’d like to tell you today. So let’s go back in time.

It’s rainy and dark. Not what you would call a cozy day on the couch or a sunny day in the park. This is more like wet concrete, flashes of lightning here and then — a thunderstorm. It is not clear to me when this piece of data will appear but I exactly know how to trigger its upcoming and where to wait for it. Willy-nilly I have to lay down and wait for the package to appear.

And then it happens: This very important piece of data suddenly is in my hands.

Now I have to bring this thing back to where I come from — back to the Future.

Back then, I wasn’t quite sure when or where to return and not even how to get this package content from this uncosy place into the bright future.

I only knew that I had to use some sort of time machine for that and most importantly, I had to assemble it and to set it up in the past, get to the Future myself, and then await the data from there.

Callback to the Future!

The Dart universe is full of Futures — we live in asynchronous times since our data can come from any other universe and time. The Dart universe wouldn’t be complete without a tool to convert these packages to our Future, without this sort of time machine. I simply had to find out. I consulted my old friend — the Doc — who knew how to solve this issue. He told me about — The COMPLETER!

Paul Nigh’s ‘TeamTimeCar.com’ Back to the Future DeLorean Time Machine by JMortonPhoto.com & OtoGodfrey.com

Now let’s get the hell out of here. I quickly return to the Future from there with the Completer.

As I told you, I had installed the Completer in the past to send the data to me and I also had to be prepared for possible failures — this was all highly theoretical and nothing proved that it would work out:

But it did. There was no failure, my mission was complete - from one moment to another - thanks to the Completer. That was it, as I said before

Little did I know how easy it finally would be.

And for all those among you who think that I should better cut a long story short: Here is how we write it in my universe, a story in 17 lines of code. I call it:

How To convert a Callback into a Future

Thank you for listening. I hope you liked it and you will from now on stick to the Future!

--

--

Nino Handler
Flutter Community

CTO & Co-Founder uryde.de | Organizer & Founder GDG Nuremberg | @luckyhandler