puniverse / pulsar

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

Selective receive breaks when spawning an actor on a redefined `defsfn` #60

Open andreasthoelke opened 8 years ago

andreasthoelke commented 8 years ago

Thank you for Pulsar, it looks amazing!

It seems I can't reload suspendable functions in the REPL. Entering this in the REPL works as expected (printing "one"):

(defsfn a1 []
  (receive
    :ab (println "one")))

(def aa (spawn a1))

(! aa :ab)

However when entering the expressions again (slightly changed) (or alternatively calling (clojure.tools.namespace.repl/refresh)), I won't see a result printed:

(defsfn a1 []
  (receive
    :ab (println "two")))

(def aa (spawn a1))

(! aa :ab)

I'm using

  :dependencies [[org.clojure/clojure "1.8.0"] 
                 [co.paralleluniverse/quasar-core "0.7.5"]
                 [co.paralleluniverse/pulsar "0.7.5"]
                 ]
  :java-agents  [[co.paralleluniverse/quasar-core "0.7.5"]]
circlespainter commented 8 years ago

This might be related to Clojure's 1.8's direct linking. Have you tried with ^:redef or ^:dynamic?

andreasthoelke commented 8 years ago

@circlespainter Thank you for the quick response!

I tried reloading

(defsfn ^:redef a1 []
  (receive
    :ab (println "two")))

and

(defsfn ^:dynamic a1 []
  (receive
    :ab (println "two")))

in clojure 1.8.0 and 1.7.0, but got the same behaviour as above.

While testing I noticed I can reload this in clojure 1.8.0 and 1.7.0!:

(def b1 (sfn []
    (receive
       :ab (println "three"))))

This should solve my immediate problem using Pulsar with the Component lib/reloaded workflow. Will test this now..

andreasthoelke commented 8 years ago

Just to confirm, as expected (def a (sfn [] ...) works fine with component/reloaded workflow, while (defsfn a [] ..) doesn't.

circlespainter commented 8 years ago

This doesn't happen with non-matching receives ((receive)).