Re: Using a try catch inside a future

2016-04-29 Thread Ashish Negi
Also, it means that bug is not in future or threads but in threaded-function itself which is swallowing all the exceptions.. Future is cancelled but it is just that bad-thread is not stopping. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post

Re: Using a try catch inside a future

2016-04-29 Thread Ashish Negi
https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Future.html#cancel%28boolean%29 may explain why future-cancelled? is returning true.. After this method returns, subsequent calls to isDone()

Re: Using a try catch inside a future

2016-04-29 Thread Dan Burton
Ah, the weirdness was because I forgot to make future-try wait for the future it creates. (defmacro future-try [& body] `(let [thread-atom# (atom nil)] (try (reset! thread-atom# (future (try ~@body))) *@@thread-atom#* (catch Exception e# (if-let [thread#

Re: Using a try catch inside a future

2016-04-29 Thread Dan Burton
Here's something to explore. (defmacro future-try [& body] `@(future (try ~@body))) (defn test-f2 [initial-v] (let [n (atom initial-v)] [n (future (while (not (Thread/interrupted)) (future-try (Thread/sleep 5000) (swap! n inc)

Re: Using a try catch inside a future

2016-04-29 Thread Dan Burton
One technique for addressing this sort of issue has been described in Haskell-land: https://www.schoolofhaskell.com/user/snoyberg/general-haskell/exceptions/catching-all-exceptions http://hackage.haskell.org/package/enclosed-exceptions I'm unaware of any comparable clojure library, but the same

Re: Using a try catch inside a future

2016-04-29 Thread Tom Bodenheimer
Hi Ashish, It actually appears that there is no exception thrown by default when future-cancel is called on the thread *unless* you manage to overlook java functions that include some type of interrupt status handling. As I managed to do. Take a look at my below test-interrupt-status-2 that

Re: Using a try catch inside a future

2016-04-29 Thread Tom Bodenheimer
Hi, this actually boils down to a strong case of read the manual and one surprising effect. The executive summary: From the Java SE 8 docs description for Thread/sleep: Throws:IllegalArgumentException - if

Re: Using a try catch inside a future

2016-04-29 Thread Ashish Negi
To stop any thread.. interrupts are send to it. And threads handle this by throwing exception so that programmer can decide what to do depending upon the kind of exception it gets. (you may get different exceptions) Since you are catching the exception, your thread is never stopped.. and

Using a try catch inside a future

2016-04-28 Thread Tom Bodenheimer
Hi all, I have recently been playing with futures and have stumbled on the following situation. (defn test-f1 [initial-v] (let [n (atom initial-v)] [n (future (while (not (Thread/interrupted)) (Thread/sleep 5000) (swap! n inc) (println