Hi James,
Interesting idea. Thanks for sharing.
I think you can simplify this:
(yoyo/run-system!
(fn [latch]
(ylet [db-pool (with-db-pool {...})
:let [server-opts {:handler (make-handler {:db-pool db-pool})
:port 3000}]
web-server (with-web-server server-opts)]
(do-this web-server)
(do-that db-pool web-server)
(latch))))
to:
(yoyo/foo! [db-pool (with-db-pool {...})
:let [server-opts {:handler (make-handler {:db-pool db-pool})
:port 3000}]
web-server (with-web-server server-opts)]
(do-this web-server)
(do-that db-pool web-server))
I believe with-* function can also be simplified further.
On Tue, Jun 23, 2015 at 1:18 AM, James Henderson <[email protected]>
wrote:
> Hi all,
>
> I've just released an early version of 'Yo-yo', a protocol-less, function
> composition-based alternative to Component. It's still in its early stages,
> so feedback would be very much appreciated!
>
> https://github.com/james-henderson/yoyo
>
> Yo-yo was also an experiment to see what could be de-coupled from the
> concept of 'reloadable systems', so you won't find any configuration,
> dependency injection, etc - just a way to write a system that can be easily
> started, stopped, and reloaded.
>
> Fundamentally, we start by assuming there's a function available that only
> returns 'when the system stops' - a 'latch', say. If we had such a
> function, we could start our system, call that function, then stop the
> system (closing any necessary resources). A database pool, for example,
> might look like this:
>
> (defn with-db-pool [db-config f]
> (let [db-pool (start-pool! db-config)]
> (try
> (f db-pool)
>
> (finally
> (stop-pool! db-pool)))))
>
> Here, we're assuming that we'll be passed 'f', the 'latch' function. A
> web server would be similar, and, because they're both functions, they're
> very simple to compose:
>
> (with-db-pool {...}
> (fn [db-pool]
> (with-web-server {:handler (make-handler {:db-pool db-pool})
> :port ...}
> (fn [web-server]
> ;; TODO: Ah. We've run out of turtles. :(
> ))))
>
> This is where Yo-yo comes in - there’s a function called run-system!,
> which takes a function that accepts a latch:
>
> (:require [yoyo])
>
> (yoyo/run-system!
> (fn [latch]
> (with-db-pool {...}
> (fn [db-pool]
> (with-web-server {:handler (make-handler {:db-pool db-pool}) ; n.b.
> we have access to the db-pool here - no need for global state!
> :port ...}
> (fn [web-server]
> (latch))))))) ; Aha!
>
> run-system! then returns a promise - deliver any value to it, and it'll
> stop the system.
>
> And that's pretty much it! There are a few more functions - mostly to do
> with easily starting/stopping/reloading a system through the REPL, and a
> macro to simplify the 'function staircase' - these are covered in more
> detail in the README. There are some also common components - a database
> pool, a web server, and a simple integration for existing Component systems.
>
> It'd be great to hear your thoughts/ideas, whatever they may be - either
> through here, e-mail, Github, or Twitter - thanks!
>
> James
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
Kind Regards,
Atamert Ölçgen
◻◼◻
◻◻◼
◼◼◼
www.muhuk.com
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.