Cedric Martin
Cedric Martin

Reputation: 6014

Are futures guaranteed to start at one point?

There may be other ways to do what I'll use as an example here, but that is not the point of my question.

I was doing this:

(future (clojure.java.shell/sh "sleep" "3" :dir "/tmp"))

To launch an asynchronous call to a shell script. ("sleep 3" is of course just an example too).

And I was wondering if the (future...) is called, is it guaranteed that at some point a thread is going to start and execute what's inside the future?

Or is this only guaranteed once dereferencing of the future is attempted?

(I know that a future which would always start only once you try to dereference it would not be very useful but that is not the point of my question: what I want to know is if it's guaranteed that a future, even if no dereferencing of that future is ever done, is guaranteed to start at one point [considering the program is still running])

Upvotes: 2

Views: 103

Answers (1)

Oleg Prophet
Oleg Prophet

Reputation: 56

It's guaranteed to send future to the ExecutorService (to clojure.lang.Agent/soloExecutor)

And it's guaranteed to be sent even if you do not attempt to dereference it (future-call source).

Upvotes: 1

Related Questions