Created
December 4, 2014 09:38
-
-
Save whostolebenfrog/357a8d081ed0a722ccde to your computer and use it in GitHub Desktop.
Clojure Exchange 2014 - resource management in clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Clojure lazy + side-effects is a little odd | |
Resources | |
- file handlers | |
- db stuff | |
This is where the problem exists in clojure as these parts aren't fun. | |
Short lived handles; | |
doall? memory, dies, heap on the floor | |
- lose beneficial laziness | |
- only works for small stuff | |
Generator function | |
- provide infinite list over resource | |
- close when we get to the end | |
- awful idea | |
Don't lie to the consumer | |
- Create file handler and give it to the user | |
- Let them deal with it | |
- Create an interface | |
Iterators; | |
- often have a close function | |
- have sequence | |
- also doesn't work! | |
- same as short lived, give the handle back to the user | |
- don't hide stuff | |
Long lived resources and concurrency | |
- db handles etc | |
- don't want to open for each request (obv) | |
Solution! (lies) | |
- lock db. heh | |
Solution! (lies) | |
- agents | |
- nope nope nope | |
- agents and atoms doing god knows what | |
Core.async | |
- channel from resource | |
- loop over incoming commands | |
- solves all his problems | |
- big loop of taking commands and doing things | |
- OH SHIT, have just reinvented actors | |
So maybe just do it like erlang | |
- except without supervisors, processors etc | |
Use Erlang! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment