Paul, Thanks... but I want the opposite of delay.
Basically, I do not want to consume a thread waiting for a Future to be satisfied. I want to continue a computation on a different thread once the Future/Promise is satisfied. Why? Think of a web app that's serving either a long poll or a web socket. Basically, you don't want to consume a thread waiting for some computation to take place. Rather, you want the computation to take place and then for the computation of sending the result to continue/resume once the computation has completed. Futures/Promises are excellent vehicles for this, especially when functions close over local scope and most of the local scope is persistant) and we use them extensively in Lift-land. I will move a lot of the stuff I've developed in Lift-land over to Clojure as many of the constructs will, I believe, play as well on Clojure as they do on Scala. Thanks, David On Thu, May 30, 2013 at 12:36 PM, Paul deGrandis <[email protected]>wrote: > I'm not entirely sure what you're trying to accomplish in a larger > context, but perhaps you're looking for something like this? > > (delay (deref (future (and (Thread/sleep 2000) (+ 1 2))))) > > ... or maybe you want just `delay` > > Cheers, > Paul > > > > On Thursday, May 30, 2013 6:09:02 AM UTC-7, David Pollak wrote: > >> Okay... I wrote my own: >> >> https://github.com/**projectplugh/plugh/blob/** >> master/src/plugh/util/misc.**clj#L51<https://github.com/projectplugh/plugh/blob/master/src/plugh/util/misc.clj#L51> >> >> One can register for on-done and on-fail. I'll work on adding fail-fast >> and also map (so one can transform the future and execute code when the >> transformed future has been realized/delivered/finished). >> >> Thanks for your help! >> >> >> >> On Thu, May 30, 2013 at 2:17 AM, Gary Trakhman <[email protected]>wrote: >> >>> by the second future, I mean an instance of http://docs.oracle.com/** >>> javase/6/docs/api/java/util/**concurrent/Future.html<http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/Future.html> >>> , >>> which just has to conform to the interface, and doesn't actually have to >>> execute on a different thread. Clojure's 'future' function returns an >>> instance of one of these that uses the unbounded agent thread-pool, but you >>> would be free to return one using reify or something. >>> >>> https://github.com/clojure/**clojure/blob/master/src/clj/** >>> clojure/core.clj#L6320<https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L6320> >>> >>> >>> On Thu, May 30, 2013 at 5:14 AM, Gary Trakhman <[email protected]>wrote: >>> >>>> Maybe an easy solution: wrap the first future in another future that >>>> blocking-derefs, then performs your extra computation? Do an extra >>>> 'realized?' check for the optimization you mention. That would still >>>> consume threads in the case that it's not realized, but I think it gets you >>>> what you want. >>>> >>>> >>>> On Thu, May 30, 2013 at 5:09 AM, Mark Engelberg >>>> <[email protected]>wrote: >>>> >>>>> According to this article, Clojure does not yet have this facility: >>>>> http://java.dzone.com/**articles/promises-and-futures-**clojure<http://java.dzone.com/articles/promises-and-futures-clojure> >>>>> >>>>> This is something that is being worked on and discussed, though: >>>>> http://dev.clojure.org/**display/design/Promises<http://dev.clojure.org/display/design/Promises> >>>>> https://groups.google.com/**forum/#!topic/clojure-dev/** >>>>> 7BKQi9nWwAw/discussion<https://groups.google.com/forum/#!topic/clojure-dev/7BKQi9nWwAw/discussion> >>>>> http://dev.clojure.org/**display/design/Async+blocks<http://dev.clojure.org/display/design/Async+blocks> >>>>> >>>>> I've been hearing a lot about Tellman's lamina library as a rich >>>>> Clojure toolset for working with asynchronicity. I haven't had a need for >>>>> it myself, but you might want to check it out and see if it has relevance >>>>> to what you want to do. >>>>> >>>>> -- >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Clojure" group. >>>>> To post to this group, send email to [email protected] >>>>> >>>>> 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<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/**groups/opt_out<https://groups.google.com/groups/opt_out> >>>>> . >>>>> >>>>> >>>>> >>>> >>>> >>> -- >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Clojure" group. >>> To post to this group, send email to [email protected] >>> >>> 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<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/**groups/opt_out<https://groups.google.com/groups/opt_out> >>> . >>> >>> >>> >> >> >> >> -- >> Telegram, Simply Beautiful CMS https://telegr.am >> Lift, the simply functional web framework http://liftweb.net >> Follow me: http://twitter.com/dpp >> Blog: http://goodstuff.im >> >> -- > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to [email protected] > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > [email protected] > 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 [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- Telegram, Simply Beautiful CMS https://telegr.am Lift, the simply functional web framework http://liftweb.net Follow me: http://twitter.com/dpp Blog: http://goodstuff.im -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] 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 [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
