Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(spawn-fiber #(rcv channel)) failing in the REPL #61

Open
andreasthoelke opened this issue Sep 9, 2016 · 0 comments
Open

(spawn-fiber #(rcv channel)) failing in the REPL #61

andreasthoelke opened this issue Sep 9, 2016 · 0 comments

Comments

@andreasthoelke
Copy link

andreasthoelke commented Sep 9, 2016

Entering the following in the REPL should return "got: 123" immediately:

; Example 1:
; With Pulsar 0.7.5
(def ch1 (channel))

(def fi1 (->> (spawn-fiber (fn one [ch] (rcv ch 10000 :ms)) ch1)
              (spawn-fiber (fn two [v] (str "got: " @v)))))

(snd ch1 123)
@fi1
;;=> "got: "

But when using Pulsar 0.7.5 @fi1 blocks until the 'rcv' times out. Though (snd ch1 123) does accept the value immediately/does not block, the rcv ch seems to never receive the value.

When I macroexpand one level and run:

; Example 2:
(def ch1 (channel))

(def fi1 (spawn-fiber (fn two [v] (str "got: " @v)) 
                      (spawn-fiber (fn one [ch] (rcv ch 10000 :ms)) ch1)))

(snd ch1 123)
@fi1
;;=> "got: 123"

I get the expected outcome: "got: 123". However if I enter the same four expressions again @fi1 blocks and I get "got: ".

If I then rename the channel the process works again:

(def ch2 (channel))

(def fi1 (spawn-fiber (fn two [v] (str "got: " @v)) 
                      (spawn-fiber (fn one [ch] (rcv ch 10000 :ms)) ch2)))

(snd ch2 123)
@fi1
;;=> "got: 123"

But I can only run this once per channel name. (This seems related to #60)

Running the following code always succeeds (in Pulsar 0.7.5 and 0.7.6) - I can enter it repeatedly in the REPL and it shows the same expected outcome:

; With Pulsar 0.7.5 or 0.7.6
(def ch1 (channel))

(def fi3 (let [fi1 (spawn-fiber #(rcv % 10000 :ms) ch1)
               fi2 (spawn-fiber #(str "got: " @%) fi1)]
           fi2))

(snd ch1 123)
@fi3
;;=> "got: 123"

With Pulsar 0.7.6 this succeeds in the first run:

; Example 1 (first run):
; With Pulsar 0.7.6
(def ch1 (channel))

(def fi1 (->> (spawn-fiber (fn one [ch] (rcv ch 10000 :ms)) ch1)
              (spawn-fiber (fn two [v] (str "got: " @v)))))

(snd ch1 123)
@fi1
;;=> "got: 123"

Also the second example succeeds as it did with Pulsar 0.7.5:

; Example 2 (first run):
; With Pulsar 0.7.6
(def ch1 (channel))

(def fi1 (spawn-fiber (fn two [v] (str "got: " @v)) 
                      (spawn-fiber (fn one [ch] (rcv ch 10000 :ms)) ch1)))

(snd ch1 123)
@fi1
;;=> "got: 123"

But entering example 1 or example 2 a second time will fail as it did with 0.7.5.
Curiously, renaming the channel does not help with 0.7.6 as it did with 0.7.5:

; Example 2 (nth run):
; With Pulsar 0.7.6
(def ch2 (channel))

(def fi1 (spawn-fiber (fn two [v] (str "got: " @v)) 
                      (spawn-fiber (fn one [ch] (rcv ch 10000 :ms)) ch2)))

(snd ch2 123)
@fi1
;;=> "got: "

(Note: I'm currently preferring 0.7.5 as 0.7.6 seems to increase REPL startup time significantly in mid-sized projects. I could document this in a separate issue if it helps)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant