Created
November 4, 2015 18:21
-
-
Save Samstiles/f42207fed19fc7e0f398 to your computer and use it in GitHub Desktop.
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
(defsfn actor-loop | |
"The function that represents our Actors, which are responsible for handling source events. Takes a list of records | |
which implement the Statistic protocol, and loops over receive until all of the records indicate they are finished." | |
[id recs] | |
(register! id @self) | |
(add-child! supervisor-actor id :transient 1 5 :sec 2000 @self) | |
(loop [records recs] | |
(if-let [event (receive [m] :else m :after actor-event-receive-timeout nil)] | |
(if-let [updated-records (actor-body records event)] | |
(recur updated-records) | |
(die)) | |
(store-actor records)))) | |
(defsfn find-records-for-context | |
"Retrieve a list of context-specific records for a particular source event." | |
[context] | |
(let [records (filter #(= context (:context %)) m/stats)] | |
records)) | |
(defsfn create-actor | |
"Creates a fresh actor for a source event." | |
[id context] | |
(println "Creating a new actor id=" id " context=" context) | |
(let [actor (spawn actor-loop id (find-records-for-context context))] | |
actor)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment