Hi,
I’m new to this community, so hello everyone!
I’m learning Julia and I get some strange output on a very simple program. I don’t understand what I’m doing wrong. Could someone help me please?
This is an experiment with a task and a channel., here is the code.
chan = Channel(1)
waiter = @task begin
while true
wait(chan)
msg = take!(chan)
println("got ", msg)
if msg == "stop" break end
end
end
sleep(2)
schedule(waiter)
println("scheduled")
sleep(1)
println("sending string msg")
put!(chan, "message")
# sleep(1)
# println("sending number msg")
# put!(chan, 123)
I get the following result below. Notice the extra double-quote that shouldn’t be there after the word message:
julia> include("test.jl")
scheduled
sending string msg
got message"
message"
And if I uncomment the last 3 lines to add a second message, it gets even weirder, the double quote disappears and the number 123 is repeated twice:
julia> include("test.jl")
scheduled
sending string msg
got message
sending number msg
got 123123
So I guess there must be something I’m doing wrong, I keep reading the docs, but I don’t understand why it behaves like this.
Julia Version 1.7.2 (2022-02-06) in a terminal of VSCode on Windows.