Fork me on GitHub
#beginners
<
2016-06-14
>
kronos_vano12:06:40

Hello!

(let [ch (chan)]
    (thread
      (job-1))
    (thread
      (job-2))
    (close-ch))
I would like to close ch after job-1 and job-2 are done. What's the best way to do it?

hrathod14:06:32

@kronos_vano: Unless you need to, it should be fine to leave the channel open until the garbage collector gets to it. See http://stackoverflow.com/questions/28888340/should-clojure-core-async-channels-be-closed-when-not-used-anymore

kronos_vano14:06:19

Yep, I know, but in my case it should be closed. For now, the best option I see is to use futures (instead of threads) and use (mapv deref futures) before calling (close! ch)

plexus14:06:00

careful: mapv is lazy so you may not get the result you want. you can use doseq instead

plexus14:06:30

you can wait for a thread to finish by joining it

plexus14:06:48

(doseq [t threads] (.join t))

bronsa14:06:33

mapv is not lazy

kronos_vano14:06:34

mapv is lazy? Are you sure?

bronsa14:06:06

but I'd rather use run! than mapv there

kronos_vano14:06:48

@bronsa It makes sense. thx

swizzard15:06:09

any recommendations for intro-to-clojurescript books, preferably ones that focus more on the -script part?

gowder16:06:47

@swizzard: it looks like Clojurescript Up and Running is due for a refresh this fall. In the meantime, maybe https://funcool.github.io/clojurescript-unraveled/ + https://github.com/magomimmo/modern-cljs

swizzard16:06:32

yeah i saw about up & running...unfortunately waiting a few months doesn't help me pad my resume now 🙂

swizzard16:06:38

but i'll look into those tutorials!

jswart18:06:17

@swizzard: learn clojure, once you have that the real challenge with clojurescript is interop with the new host (javascript). I would write some small apps that do some interop with other js libraries. Other than that once you know clojure its pretty straightforward. Understanding popular JS libraries and how to work with them in CLJS is the sticking point.

dmbennett18:06:51

Hey folks, trying to get a better idea of how to use the -> operator and had some trouble thinking through nested anonymous functions

dmbennett18:06:23

could someone help me understand what it would look like to use the -> with the following function:

(defn item-dates
  "filters returns the two relevant fields from jira response"
  [hist]
  (map #(select-keys % [:items :created]) hist))

swizzard18:06:24

@jswart i've been learning/using clojure for a few years, i was just looking for some stuff that has specific pointers on js interop and like, thinking clojurically about web stuff

swizzard18:06:46

@dmbennett: that's not a great candidate for -> really

dmbennett18:06:12

is it a bad idea to use the map function with ->?

swizzard18:06:17

not necessarily

swizzard18:06:47

it's just that -> is useful only when there's multiple functions involved

swizzard18:06:06

and their signatures aren't amenable to something like comp

jswart18:06:54

@swizzard: most people in CLJS seem to like React and a CLJS flavor. If you can do react in CLJS you are likely okay. If you can build a CLJS frontend that reliably talks to the CLJ backend then you will be hired (anecdotally speaking).

swizzard18:06:43

@jswart: that's in line with my hypotheses 🙂

swizzard18:06:01

right now i've got a personal project that's an es6 SPA talking to a python-backed REST api, and it's getting out of hand

swizzard18:06:49

i could capitulate and go with some js framework, but i'd rather learn/practice cljs than whatever the flavor-of-the-month js mvc thing is

dmbennett18:06:51

anyone know of the most idiomatic design pattern for constructing urls in clojure? Ex. I have a base url, I need to iterate through a variety of relative URLs, and I have some params

dmbennett18:06:04

In ruby I would use string interpolation

donaldball18:06:39

Some folk do strings, some folk do java.net.URI interop