Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add supervisor implementation to joxa.otp
Signed-off-by: Jordan Wilberding <diginux@gmail.com>
- Loading branch information
1 parent
9931723
commit ee5af16
Showing
2 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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))) |