Fork me on GitHub

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[ 0x2fc9a402 "/tmp/ring-multipart-11354728889402997926.tmp"], :size 55}}
this is map of my request, i don't understand this part #object[ 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 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 to your ns form.


oh wait let me try that


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


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?


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.


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.


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.


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.


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


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


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


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.


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

👍 1

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.