Processing futures and promises asynchronously

184 views
Skip to first unread message

Daniel Hinojosa

unread,
Oct 26, 2015, 6:46:27 PM10/26/15
to Clojure
I am looking for a functional, non-blocking way to process the return of a future. In the Scala world, you can use map, flatMap, and foreach to process the return values of a future asynchronously.  In Clojure, dereferencing blocks, so that makes it kind of rough since we have to set up our constructs.  If anyone can steer me on the "Functional Clojure way" to process futures and promises that would be greatly appreciated. ;)

Leonardo Borges

unread,
Oct 26, 2015, 6:51:47 PM10/26/15
to Clojure
Hi Daniel,

Since you're used to Scala futures, you might find this library easy to get started with:

https://github.com/leonardoborges/imminent (A composable Futures library for Clojure)

The next release will also include ClojureScript support.

Cheers,
Leonardo Borges

On Tue, Oct 27, 2015 at 9:46 AM Daniel Hinojosa <dh.evolu...@gmail.com> wrote:
I am looking for a functional, non-blocking way to process the return of a future. In the Scala world, you can use map, flatMap, and foreach to process the return values of a future asynchronously.  In Clojure, dereferencing blocks, so that makes it kind of rough since we have to set up our constructs.  If anyone can steer me on the "Functional Clojure way" to process futures and promises that would be greatly appreciated. ;)

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matching Socks

unread,
Oct 26, 2015, 7:31:57 PM10/26/15
to Clojure

Chris Murphy

unread,
Oct 26, 2015, 7:48:29 PM10/26/15
to clo...@googlegroups.com

Here are some discussions around the issue:

http://stackoverflow.com/questions/31832599/future-failure-in-clojure

~ Chris
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient
> with your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to clojure+u...@googlegroups.com
> <mailto:clojure+u...@googlegroups.com>.

Alejandro Gómez

unread,
Oct 27, 2015, 5:38:45 AM10/27/15
to clo...@googlegroups.com
Hi Daniel,

Allow me to recommend a couple of libraries:
- promissum (https://github.com/funcool/promissum) is a composable
promise/future library for Clojure (built on top of jdk8 completable
futures)
- promesa (https://github.com/funcool/promesa) is a wrapper around the
Bluebird JS promise library

They both integrate nicely with cats (https://github.com/funcool/cats),
which lets you write asynchronous code like it was synchronous with the
`mlet` macro that desugars into monadic bind. We also have an `alet`
macro that uses applicative bind and thus maximizes concurrency, take a
look at the docs for more details.

cats is also integrated with core.async and manifold libraries, so you
can use the same code regardless of what concrete type you use for
conveying asynchronous values.

Regards,

Al
> email to clojure+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
Alejandro Gómez
alej...@dialelo.com

Daniel Hinojosa

unread,
Oct 27, 2015, 1:28:39 PM10/27/15
to Clojure
Amazing feedback everyone. Thank you.

Stuart Sierra

unread,
Oct 28, 2015, 8:10:34 AM10/28/15
to Clojure
core.async and Transducers target some of this, although in a slightly different way. Instead of clojure.core/future, you can use core.async/thread or core.async/go. Instead of flatMap, you can use a `map` Transducer on a channel or in a core.async/pipeline.

–S
Reply all
Reply to author
Forward
0 new messages