puniverse / pulsar

Fibers, Channels and Actors for Clojure
http://docs.paralleluniverse.co/pulsar/
Other
911 stars 53 forks source link

Watching actors from a gen-server #67

Closed sandhu closed 8 years ago

sandhu commented 8 years ago

My understanding is that a gen-server with a watch! on an actor should receive a message via it's handle-info when the watched actor terminates.

The following example is based on code from the tests and my expectation is that both actor2 and gs should receive messages indicating that actor1 has terminated.

On running, actor2 does indeed receive the exit, but gs does not receive anything.

(let [actor1 (spawn (fn [] (Fiber/sleep 2000)))
      actor2 (spawn (fn []
                      (let [w (watch! actor1)]
                        (receive
                            [:exit w actor reason] (println "actor2: got :exit")))))
      gs (spawn
          (gen-server (reify Server
                        (init [_]
                          (println "GS: init called")
                          (set-state! {:watch (watch! actor1)}))
                        (terminate [_ cause]
                          (println "GS: terminate called"))
                        (handle-info [_ message]
                          (println "GS: handle-info called")
                          (println message)))))
      gs-term (spawn (fn []
                       (Fiber/sleep 5000)
                       (println "Shutting down GS")
                       (shutdown! gs)))]
  (join actor1)
  (join actor2)
  (join gs)
  (join gs-term))

Help on this issue would be greatly appreciated.

Thank you.

pron commented 8 years ago

Should work now in the snapshot version.

sandhu commented 8 years ago

Thanks. Will try it out.