Skip to content

Commit

Permalink
add supervisor implementation to joxa.otp
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Wilberding <diginux@gmail.com>
  • Loading branch information
ericbmerritt authored and jwilberding committed May 2, 2012
1 parent 9931723 commit ee5af16
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion build-support/core-build.mkf
Expand Up @@ -23,7 +23,8 @@ SRCBEAMS= $(BEAMDIR)/joxa/compiler.beam \
$(BEAMDIR)/joxa/lists.beam \
$(BEAMDIR)/joxa/build-support.beam \
$(BEAMDIR)/joxa/otp.beam \
$(BEAMDIR)/joxa/otp/application.beam
$(BEAMDIR)/joxa/otp/application.beam \
$(BEAMDIR)/joxa/otp/supervisor.beam

TESTBEAMS = $(BEAMDIR)/jxat_anon_fun.beam \
$(BEAMDIR)/jxat_examples.beam \
Expand Down
33 changes: 33 additions & 0 deletions src/joxa/otp/supervisor.jxa
@@ -0,0 +1,33 @@
;;; Supervisor Behaviour Support
;;; ============================
;;; * author: Eric Merritt
;;; * copyright: Erlware, LLC 2012
(module joxa.otp.supervisor
(require erlang supervisor joxa.lists))

(defmacro+ gen-start-link ()
;; Create a default start link function for the most common
;; supervisor start method
`(defn+ start_link ()
(supervisor/start_link {:local ($module-name)} ($module-name) [])))

(defn+ default-init (child-list)
;; Create a default supervisor spec based on a list of child
;; modules.
{:ok {{:one_for_one 1000 3600}
(joxa.lists/foldl (child child-list)
(acc [])
({child {child :start_link []}
:permanent 2000 :worker [child]} . acc))}})

(defmacro+ gen-init (child-list)
;; Create an entire default init based on a list of child modules.
(let (args (joxa.core/gensym "supervisor"))
`(defn+ init (~args)
(joxa.otp.supervisor/default-init ~child-list))))

(defmacro+ gen-supervisor (child-list)
;; Gen an entire supervisor body from the hild list
`(do
(joxa.otp.supervisor/gen-start-link)
(joxa.otp.supervisor/gen-init ~child-list)))

0 comments on commit ee5af16

Please sign in to comment.