Book Image

Clojure Reactive Programming

Book Image

Clojure Reactive Programming

Overview of this book

Table of Contents (19 chapters)
Clojure Reactive Programming
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Bibliography
Index

core.async


If you've ever done any amount of JavaScript programming, you have probably experienced callback hell. If you haven't, the following code should give you a good idea:

http.get('api/users/find?name=' + name, function(user){
  http.get('api/orders?userId=' + user.id, function(orders){
    orders.forEach(function(order){
      container.append(order);
    });
  });
});

This style of programming can easily get out of hand—instead of writing more natural, sequential steps to achieving a task, that logic is instead scattered across multiple callbacks, increasing the developer's cognitive load.

In response to this issue, the JavaScript community released several promises libraries that are meant to solve the issue. We can think of promises as empty boxes we can pass into and return from our functions. At some point in the future, another process might put a value inside this box.

As an example, the preceding snippet can be written with promises like the following:

http.get('api/users/find...