his seems strange to me:
We're trying to call the submit(Callable) method on the ExecutorService,
passing in a Clojure function.
First of all we use an executor in a global def, and submit a function, and
it appears to use the submit(Runnable) method i.e. we're getting nil
instead of the result of the function.
OK then, let's add a type hint to the function before submitting it, but it
seems to have no affect.
Then we try an executor in a local let, and it starts to work - giving
reasonable responses with and without the type hint.
Why does the way we refer to the executor make a difference here? Any
insight appreciated!
; nREPL 0.1.4-preview
user> *clojure-version*
{:major 1, :minor 4, :incremental 0, :qualifier nil}
user> (def exe (java.util.concurrent.Executors/newSingleThreadExecutor))
#'user/exe
user> (.get (.submit exe (fn [] (+ 1 1))))
nil
user> (let [^java.util.concurrent.Callable my-fn (fn [] (+ 1 1))]
(.get (.submit exe my-fn)))
nil
user> (let [exe (java.util.concurrent.Executors/newSingleThreadExecutor)]
(let [my-fn (fn [] ( + 1 1))] (.get (.submit exe my-fn))))
CompilerException java.lang.IllegalArgumentException:
More than one matching method found: submit, compiling:(NO_SOURCE_PATH:2)
user> (let [exe (java.util.concurrent.Executors/newSingleThreadExecutor)]
(let [^java.util.concurrent.Callable my-fn (fn [] ( + 1 1))] (.get
(.submit exe my-fn))))
2
user>
--
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