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.

RECAP

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 ].

OVERVIEW

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). Macrohttps://github.com/knoldus/macros-example

2). async-awaithttps://github.com/knoldus/async-await-example

References ->

1). http://docs.scala-lang.org/sips/pending/async.html

2). http://docs.scala-lang.org/overviews/macros/overview.html

3). http://docs.scala-lang.org/overviews/reflection/overview.html

4). http://www.warski.org/blog/2012/12/starting-with-scala-macros-a-short-tutorial/

Happy coding …

This entry was posted in Scala and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s