This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-24
Channels
- # adventofcode (2)
- # anglican (1)
- # announcements (4)
- # aws (2)
- # babashka (28)
- # beginners (18)
- # brompton (3)
- # calva (22)
- # clj-kondo (2)
- # cljdoc (29)
- # clojure (41)
- # clojure-europe (28)
- # clojure-gamedev (14)
- # clojure-nl (2)
- # clojure-spec (2)
- # clojure-sweden (1)
- # clojure-uk (6)
- # clojurescript (53)
- # css (3)
- # cursive (6)
- # duct (3)
- # emacs (5)
- # fulcro (29)
- # introduce-yourself (1)
- # liberator (5)
- # lsp (1)
- # malli (11)
- # meander (4)
- # nbb (11)
- # off-topic (17)
- # pathom (2)
- # polylith (8)
- # practicalli (1)
- # react (6)
- # reagent (11)
- # releases (2)
- # rewrite-clj (11)
- # shadow-cljs (59)
- # tools-deps (21)
- # vim (11)
what happens to unclaimed future results? If I spawn a future and abandon it (say the future stores its result somewhere), and the future creator never derefs the future, what happens to the result? Does it just consume memory in the JVM forever more? Is it gabage collected somehow when the creator returns without the future?
It will be available for garbage collection:
> (future
(reify
Object
(finalize [_]
(println "goodbye"))))
#<Future@18bd51a8:
#object[$eva...66"]>
> (System/gc)
goodbye
user=> (def fut
#_=> (future
#_=> (reify
#_=> Object
#_=> (finalize [_]
#_=> (println "goodbye")))))
#'user/fut
user=> fut
#object[clojure.core$future_call$reify__8439 0x68d96261 {:status :ready, :val #object[user$fn$reify__2006 0x35c59975 "user$fn$reify__2006@35c59975"]}]
user=> (System/gc)
goodbye
nil
user=> fut
#object[clojure.core$future_call$reify__8439 0x68d96261 {:status :ready, :val #object[user$fn$reify__2006 0x35c59975 "user$fn$reify__2006@35c59975"]}]
user=> @fut
#object[user$fn$reify__2006 0x35c59975 "user$fn$reify__2006@35c59975"]
It will be available for garbage collection when there aren't any references pointing towards it
but printing “goodbye” means something have been gc’d right when fut
was live?
i see an other “goodbye” after
(def fut nil)
(System/gc)
(def fut
(future
(reify
Object
(finalize [this]
(println (.hashCode this))))))
=> #'finaliz/fut
(System/gc)
1723828443
=> nil
(.hashCode @fut)
=> 822250702
(def fut nil)
=> #'finaliz/fut
(System/gc)
822250702
=> nil
To keep two maps in sync I guess the easiest thing to do is to create an atom with two fields that contain the maps like :state->jobids
and :jobid->state
, right? And then ensure that all operations keep them in sync
Let's say I have an atom like above with
{:jobid->state {:jobid1 :ready :jobid2 :in-progress ...}
:state->jobids {:ready #sorted-set{:jobid3 ...}}
:in-progress #sorted-set{:jobid4...}
:done #sorted-set{:jobid5 ...}}
Is there any advantage in making it a defrecord? Or is that only advantageous if I want polymorphism? I do Scala at work so there I'd make it an object. But I guess there is no advantage to it here. I could just have it in a namespace with the getter/setter/lookup-functions.I don’t really see any benefit in turning this into a record. You already have it properly structured with nice names and all that and Clojure’s APIs work best with this kind of data 🙂 If you need Java interop then maybe, but as is, nah.
That is what I thought. Thanks! 🙏
Hey everyone. I’ve got a seemingly very basic question: I want to attach a Thread$UncaughtExceptionHandler
to the current thread (my main thread). I do this via
(ns exception-test.core)
(defn -main
[& args]
(Thread/setDefaultUncaughtExceptionHandler
(reify Thread$UncaughtExceptionHandler
(^void uncaughtException
[^Thread$UncaughtExceptionHandler this ^Thread t ^Throwable e] ; -> void
(println "caught:" (.getMessage e)))))
(throw (Exception. "this is the ex"))
(println "after ex"))
My expectation would be that the "this is the ex"
expection is caught, but it isn’t. Maybe someone can help me out here?
are you testing your main
function in REPL?
No, I’m calling it from the shell via clojure -M -m exception-test.core
ok, that isn’t working because of https://github.com/clojure/clojure/blob/master/src/clj/clojure/main.clj#L650-L672 exception thrown by your code will be catched by clojure’s main function
Thanks a lot. I just figured out the same thing.
Hi, Clojurians.
I’m Younghwan Nam.
I’d love to ask about AWS lambda layer where I am stuck in.
in deps.edn
, I’d like to know how to add sth like scope : provided
.
I’m considering Lambda Layer to separate dependencies. after making layer, I was trying to make uberjar
to deploy lambda. but because of aot: true
dependencies are necessary. I have no idea how to deal with it.
Thanks a lot.
Here is my dep.edn
for application.
{:paths ["src" "resources"]
:deps {org.clojure/clojure {:mvn/version "1.10.3"}
com.amazonaws/aws-lambda-java-core {:mvn/version "1.0.0"}
com.amazonaws/aws-lambda-java-events {:mvn/version "1.0.0"}}
:aliases
{:dev {:extra-deps {clojure.java-time/clojure.java-time {:mvn/version "0.3.2"}}}
:uberjar {:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.0.211"}}
:exec-fn hf.depstar/uberjar
:exec-args {:aot true
:jar "lambda-demo.jar"
:main-class "yhnam.lambda-demo"
:sync-pom true}}}}
I'd say that scope provided
is something for libs to use, not applications
If you need to make a dependency optional, you can simply isolate it via the :aliases mechanism
e.g. it can be present under the :dev alias but otherwise absent by default.
Anyway I'd recommend taking a step back and describing your problem more precisely, before considering any specific solution
So basically you want to compile your AOT code with some dependency on the classpath and then make an uberjar with that dependency not on the classpath
depstar
supports different sets of aliases for compilation and for JAR-building, which was added specifically for this use case.
:aliases
and :compile-aliases
are the exec arguments you need but you'll need to ensure that what you need for compilation is added via an alias, so that you can tell depstar
"compile it with these dependencies" and then "build it with these different dependencies".
https://github.com/kwladyka/consistency-clj/blob/master/deps.edn here is example of real code for compile to uberjar and publish to clojars consider just use https://clojure.org/guides/tools_build#_parameterized_build . I didn’t have a chance to try, but looks like it can be new standard.
@U0WL6FA77 That is not a useful example: it does not involve :aliases
or :compile-aliases
for depstar
which is what the OP needs.
it is worth to look on number of threads in the process. if it is growing in time it can means something not close properly.
It is impossible to defrecord
with the same name as a class in java.lang
, right?
E.g. (defrecord Enum [])
fails with Enum already refers to: class java.lang.Enum
.
not sure if there's a cleaner way
Seems like the best idea I can think of