puniverse / pulsar

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

Blocking and bound mailboxes - not working as expected #75

Closed markjfisher closed 7 years ago

markjfisher commented 7 years ago

I may have understood this incorrectly, but when I send messages to an actor that has a bounded sized mailbox with a overflow policy of block, it doesn't appear to block and instead I'm getting QueueCapacityExceededException.

A simple example is:

(defsfn handler-sfn []
        (loop []
          (receive [m]
                   [:message data] (do (infof "received data: %s" data)
                                       (sleep 50))
                   :else
                   (infof "Unknown message received in handler-sfn - %s" m))
          (recur)))

(defsfn adder-sfn [handler]
        (dorun (for [x (range 100)]
                 (do (infof "sending message %s" x)
                     (! handler [:message x])))))

(defn -main
  []
  (let [handler (spawn :mailbox-size 10 :overflow-policy :block handler-sfn)
        adder   (spawn adder-sfn handler)]
    (join handler)))

If I remove the mailbox-size and overflow-policy, the example works, it sends 100 messages, and receives them all, as does setting the mailbox size to >100 as it doesn't fill up. However, as it stands the sending doesn't block, and the exception is thrown.

What's the correct way to block the sender in this case?

pron commented 7 years ago

See puniverse/quasar#283

markjfisher commented 7 years ago

Thanks for the response @pron.