Fork me on GitHub

@noisesmith , I thought of that too and figured it would be the best way. I've begun building my functions out that way but I guess my concern is, should I use a future for a single thread of my app? Basically what I have is I get a connection from a client, and then I want to just continue processing data coming in and going out of that stream indefinitely until otherwise noted.


But somehow I guess it just mentally feels odd that that's how I would go about handling the process? Maybe that's just in my head though.


that seems reasonable except thread-per-client is fragile (unless you strictly limit client count)


Yeah this isn't a billion client application. Just something really simple with 5 clients connecting into my server app sending data back and forth.


you can use stuartsierra’s excellent component library to manage data and resources and state that need to be shared between code in different namespaces without needing to create global singleton data


there are other alternatives people have made as component replacements too, but component is the one I have used and it works well


Awesome I'll take a look at that as a jumping off point; thank you.


So I just ended up calling the main source directly, instead of the stub file. Seems to have worked.


@mbcev I feel like you've got the perfect use case for Dynamic Vars


@mbcev You need thread global variables correct? If so, that's what those are for exactly


@didibus actually what I was aiming for was the exact opposite. I wanted to make sure my data was isolated. What I had been doing was clumping all my "processing" code in one namespace for organizational purposes and then while repl dev-ing I created an atom that I could work on as I added/tested functions. But I don't need the atom anymore now that everything works as intended. I just pass the vector of maps in as a functional argument and my functions pass that around and work with it as necessary.


But when I was looking at stuarsierra/compontents and doing some more research I actually stumbled on Dynamic Vars.


So I appreciate the input also! They're not what I need for this project, but I've added them to my toolbelt!


@mbcev Well, you want it isolated at what level? At the thread level, or more granular?


They'll give you thread isolation mutable globals


thread isolated*


@didibus well I don't know what is idiomatic I guess, but the way I'm "used to" thinking about things is the "everything is an object" world of Java. So when it comes to organizing my code now I have to consciously make an effort to remember that a namespace isn't equivalent to a java class/object.


So what I wanted was to put all my "processing" code in one namespace and all my networking code in another namespace.


My networking code gets clients and then spins up a future that starts off the processing code


It sounds like you probably didn't need a global, and that's probably for the best. They'd be useful if you needed multiple functions to share the value, but you did not need to share it between threads.


Yeah, I don't need any sharing between the threads in this case.


What about between the functions?


So, dynamic vars do not share across Threads. They're a bit like a ThreaLocal


In a Java Class/Object what I'd do is have my private ArrayList MyObjName let's say and then my functions could be written to freely call MyObjName without me needing to worry about Client 1 messing with Client 2 because all the code and data is encapsulated


So I just wanted to figure out what the "right" way of doing that would be with Clojure, what I have ended up doing is having a (start-process [structure, clientID]) function in which I pass my data structure and which client stream and then let the functions do their thing


so I took out the (def data atom []) that I was using before


Could Client 1 and Client 2 share a thread? If not, you can do the same thing you'd do in Java with dynamic vars. Though it would probably be more idiomatic if you didn't use global variables and had every function take all input as argument.


I feel you ended up with the most idiomatic solution.


Thou just an FYI, dynamic Vars give you thread isolation. They're thread safe basically


Uhh, I'm sure they could share the same thread. I'm just not good at Clojure yet haha.


So it just kind of made more sense to me to let them do their own thing.


makes sense


I'm using ztellman/manifold for the stream abstractions and pooled queues. So honestly I probably didn't even need to use futures the way I did.


I'm just not entirely familiar with how all the individual components of what I'm doing work so I'm sure a more experienced dev could clean up or optimize what I'm doing.


Uh, didn't knew about manifold, looks pretty cool


Ya, it sounds like you managed to figure out something pretty good on your own


I know just enough Clojure to be dangerous haha.


You can definitely shoot yourself in the foot. But I think Clojure is pretty good at not letting you do that.


Unless you start writing a bunch of macros


don't do that


I own a few of the great books out there and have read each of them at least twice, have been following the community for a few years, and have watched plenty of the conferences on youtube so I have developed some sense of "idiomatic clojure", but I don't have tons and tons of actual use-case experience.


Ya, I've done some work projects in Clojure, but even I feel I only know the surface. If its a use case that's different from what I did, I'm lost again. Like never had to use core.async, or do any kind of web work, so these parts are obscure to me.


Barely touched core.logic


Darn the alarm, I can never demo things 😞


@didibus I'm playing with it now yeah. Awesome! Thanks! Learned something new.


But ya, generally, would be better to just have increment-to-10 take a counter, instead of modifying a global, even though that global is thread safe.


Yeah 99% of what I'm doing can be done immutably so I don't need a mutable global or anything like that. The only reason I did need to keep track of state basically was to keep track of how much data my client had sent vs how much the server thread had received so that if necessary, the client could go back and resend missing data.


Ya, that's an interesting problem. Like you need a place to track progress, the progress could be updated by multiple threads, and the number of clients is dynamic.

Drew Verlee19:04:36

If i wanted to use the max function to find the max of something that wasn’t already defined, how would i go about doing that? extending the max function?

Drew Verlee19:04:30

i know it would be easy to sort then take the first.

Drew Verlee19:04:20

hmm i guess max is just intended for numbers.

Alex Miller (Clojure team)20:04:15

you might look at max-key