O'Reilly logo

Clojure for Finance by Timothy Washington

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Consuming from a data stream

In order to consume from an infinite stream of data, let's review the approaches discussed in Chapter 6, Surveying the Landscape.

Futures and promises only offer a one-time asynchronous task and are not suitable in this case. Also, we need some kind of list into which a data producer can insert ticks and analytics data. A consumer of this data would then be able to asynchronously take from the list. This is what a queue provides conceptually.

The clojure.lang.PersistentQueue/EMPTY option is nonblocking. So, if there's no data in a queue, the consumer would have to continuously ask for data until it arrives (known as polling). This is not quite what we want. Ideally, the consumer should wait (or block) until the data ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required