Fork me on GitHub
Lucas Barbosa02:10:26

Is it safe to share Java objects between threads in clojure?

Lucas Barbosa02:10:38

a client Socket, for instance

Lucas Barbosa02:10:55

like (future (handle-client socket))

Lucas Barbosa02:10:51

I’m not doing concurrent access, but I am worried about stale data, for instance


if nothing else uses the socket, it's safe


I have a working app with a clojure + clojurescript application. The backend serves the initial HTML, with the base components. The frontend makes AJAX calls to the backend, which has couple of API endpoints, and then the components get reloaded with the response data. The AJAX calls works fine this way with a production cljs build, where the HTML is being served by the same port as the API endpoints. My newbie question: how can I make the AJAX calls work when the HTML is being served by figwheel. (The port is being used figwheel, so I can't use it to serve the backend)


@raheel Not sure if the #figwheel or #lein-figwheel channels might be more able to help? It's a bit late for most folks to be around (10pm Pacific; 1am Eastern) -- maybe ask again earlier tomorrow?


thanks @seancorfield. I am probably very fuzzy about the concepts here, but managed to solve this for now: run the server and figwheel on separate port. Navigate to the figwheel port in the browser and let it connect. Then navigate to the server port in the browser, and reloading works in that page as well.


that's how dev workflow should work, @raheel with figwheel running dev mode on default 3449, and server backend running on default 3000, great that you've already figured that out 🙂


anyone knows some kind of binding that executes #(-> % f g h)


something like fn-> ?


nvm, that's just comp :thinking_face:


@qle-guen it is comp, except that function composition is right-to-left, so for the example you gave it would be (comp h g f)


yes but from what I understand of it, partial application is different from threading


because threading just inserts the argument at the end of the list


or at the second place with ->


indeed you are - however in your example you wrapped the threading macro in an anonymous function; and when everything you're threading the data through are functions, then that is equivalent to function composition


comp isn't partial application fyi, you just pass the results from each function call to the next - like you did with the threading macro


partial application would be (def add-six (partial + 6))


yes, it's because I come from Haskell where everything is curried


ah right, fair enough!


so I'm not really used to think about these distinctions




@qle-guen FWIW, my util lib has that exact macro. (defmacro fn-> [& forms] (fn [x#] (-> x# ~@forms))) (the body is syntax quoted, which I don't know how to escape in slack...)


Not specific to clojure necessarily, anyone seen a good example of not using sessions for authentication for a rest api on a SPA? Tried the following: 1) Using fb login client side, which then passes token to server, which validates token and creates jwt token for app. This works, but all of a sudden stopped on my android phone browser. 2) Used browser redirects to fb login, but once i authenticate, not sure how to redirect back to my app without a session. Seems i should use an https cookie to store the token, but coludn't find how the buddy auth lib validates against a cookie (I could write it myself i guess) So yeah, been reading, and watching an looking at examples. But none seem to be complete front-end and backend auth. though i'd ask here to makes sure i didn't miss anything obvious.


Thanks @lovuikeng I am using buddy. Looking for something that shows client/server side auth with an external auth service. fb, auth0. Maybe there is part of it that i missed though, will keep reading.


@lovuikeng That does show how to use the cookie to store the jwt, so might get me closer to writing one. thanks.