Fork me on GitHub
#beginners
<
2020-06-06
>
ludociel11:06:49

hola amigos im new to java, clojure and ring. so i'm trying to extract an information but i haven't found any resources on google

{:file {:filename "fdf.txt", :content-type "text/plain", :tempfile #object[java.io.File 0x2fc9a402 "/tmp/ring-multipart-11354728889402997926.tmp"], :size 55}}
this is map of my request, i don't understand this part #object[java.io.File 0x2fc9a402 "/tmp/ring-multipart-11354728889402997926.tmp"]. my only understanding is that this is a java Object ? i want to extract the string "/tmp/ring-multipart-11354728889402997926.tmp" out of that, any idea how to do that?

Dan Boitnott11:06:06

What you have there is a https://docs.oracle.com/javase/7/docs/api/java/io/File.html instance and I'm guessing you want to extract it's absolute path as a string?

Dan Boitnott11:06:10

If so, then you'll want something like:

(.getPath (:tempfile my-map))

Dan Boitnott11:06:39

You'll probably also need to add an import for http://java.io.File to your ns form.

ludociel12:06:42

oh wait let me try that

Lukas21:06:51

Hey how can I prevent my program from closing, when I start it from the console?

Lukas21:06:52

I have a scheduled job in it that puts data on a channel, but it just closes instantly before processing any data. (while true) works but my pc doent like it. Is there a more lightweight way to do it?

gerred22:06:06

yeah, while true is obviously not going to throttle in any useful way in-and-of-itself and will happily consume a CPU core. one way to go about this would be to have a second channel you take (`<!!`) on, and when you're done with what's happening in your go block, send a value (maybe an error), or just close that channel.

gerred22:06:44

another way would be to use something like promesa, do very much the same thing, and deref the promise - and resolve that promise once you're done with your async work.

gerred22:06:55

yet another way would be to just block synchronously - and that's the most simple option if you don't need multithreading. depending on what you're doing, async/multithreading can actually slow you down - or, at the very least, your async code will be dependent on your slowest execution path.

gerred22:06:31

yet another way 😉 if you're using CLJS with Node - the Node event loop will block until all event handlers have been removed. so you could create some arbitrary event handler using once and trigger that event when done.

gerred22:06:01

oh, and a crude way would be to add some Thread/sleep to your while true

gerred22:06:16

i'm sure others will think of many other useful ways to do this as well!

bartuka22:06:22

rsrs at that point where you need more info to go further 🙂

Lukas22:06:30

I used a asynch channel with timeout but I swapped it out now with Thread/sleep inside the loop. That will work for now. Thanks.

seancorfield23:06:25

I usually have a promise inside my (long-running) processes and just "wait" on it in -main (via a deref).

👍 1
seancorfield23:06:59

Normally, that will just "wait forever" but if you start a REPL in the server, you can connect to it and deliver the promise to cause it to shutdown, or you could program some external action in your server that also delivered the promise to cause it to shutdown.