Getting Asynchronous in Scala : Part 2 (macro, reflection and Async library)

“Our patience will achieve more than our force.” – Edmund Burke

The thought above tells about the beauty of being patient. One of the most important trait of a programming language is to be patient for the code segments to complete their execution asynchronously.

In this blog we will continue with the Async library and some prerequisite associated with it.


In first blog of ‘Getting asynchronous in Scala’ series we discussed about Futures, how to access them (callbacks, for comprehensive, Await.result) and how to handle exceptions associated with them (combinators). To refer the first blog [HIT ME ].


In this blog we will be understanding how async await are used and implemented (using macros, reflection) in Scala.

We will start by first discussing what macros are and how to use them. Along with it reflection will be discussed as macros are internally implemented using reflection. So two major checkpoint of the remaining voyage are :-

1). Macros and reflection
2). The Async library in Scala

Inspired by “Let it crash! – the Akka team blog” (second blog of issue #125 of the Scala Times), this blog is also written in modular approach(Good Stuff Akka Team). The first checkpoint holds the link to the basic stuff(macro and reflection) that must be known to understand the implementation of the Async library and the second checkpoint has the detailed description of Async library.

P.S. – (yes they are published by me only :p ).

Checkpoint 1 ‘Macros and Reflection’ -> (Foundation for Async library)

Blog Link – Macros in Scala

The blog in the above link tell what macros are and how they function. It lays a foundation on which we will construct the understanding of the Async library. Please see that this blog only gives an overview of macros so that we can understand Async library and does not has detailed description of macros.

Checkpoint 2 ‘The Async library in scala’ -> (Finally…)

Blog Link – The Async library in Scala

The above blog explains how the ‘async’ and ‘await’ method of the Async object are used and internally implemented. Using example, use case of async and await is explained and limitations where they cant be used are demonstrated. Then the transformations undergone by the code under the ‘async’ scope are explained thus giving an overview of how things work when we use ‘async’, ‘await’ for coding asynchronously.

Git code for both the checkpoints can be found at :-

1). Macro

2). async-await

References ->





Happy coding …

Written by 

Sahil is a Software Consultant, with experience of more than 2.5 years. He is Microsoft certified c# developer. He has sound knowledge of different technologies which include C#, C, SQL, Scala, Play, ANTLR4, Docker, Ansible, jenkins, Python, DataDog, Promethous, Lightbend Telemetry etc. His hobbies include of cooking , watching anime and Partying with friends.

Leave a Reply

%d bloggers like this: