puniverse / pulsar

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

Messages appear not to be received in a case involving passing @self to a newly spawned actor right before (recur) #28

Closed roman-himself closed 9 years ago

roman-himself commented 9 years ago

I may have come across a bug in a peculiar case I was trying to implement. Take a look at this expression:

(let [timer-fn (sfn [boss timeout msg]
                      (receive
                        :cancel nil
                        :after timeout (! boss msg)))
        print-actor (spawn #(do
                             (println (receive))
                             (spawn timer-fn @self 1000 :tick)
                             (recur)))]
    (! print-actor :tick))

This spawns a print-actor that continually prints the received message and spawns a timer actor which signals it after some time and dies. After setting the machine in motion in the last line you would expect print-actor to print :tick to the console in 1 second intervals, but this does not happen. From my investigation it seems that in this case the timer is spawned correctly and does send the message, only for some reason print-actor doesn't receive it.

circlespainter commented 9 years ago

As a temporary workaround, turning the do into a let and binding @self to a symbol instead of passing it directly to spawn restored the expected behaviour for me.