Why is process.receive not receiving messages? #4083
Answered
by
lpil
Lilja
asked this question in
Questions & support
-
I'm trying to understand more about subjects and selectors. I made this short snippet, but it's not receiving anything. Why is that? What am I missing? import repeatedly
import gleam/erlang/process
pub fn main() {
let subject = process.new_subject()
repeatedly.call(5000, Nil, fn(_state, _i) {
io.debug("Checking for messages")
case process.receive(subject, within: 5000) {
Ok(msg) -> {
io.debug("Received message " <> string.inspect(msg))
}
Error(_) -> {
io.debug("No message")
}
}
io.debug("Done listening")
Nil
})
repeatedly.call(1000, Nil, fn(_state, _i) {
io.debug("Sending message")
process.send(subject, "Hello")
})
process.sleep_forever()
} Logs:
|
Beta Was this translation helpful? Give feedback.
Answered by
lpil
Dec 15, 2024
Replies: 1 comment 2 replies
-
The subject does not belong to the process you are attempting to receive using. You should also ideally not use the repeatedly library like that, instead create a regular process or use the actor module. It's a tool for cross platform scripts and not a building block for OTP programs. |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
Lilja
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The subject does not belong to the process you are attempting to receive using.
You should also ideally not use the repeatedly library like that, instead create a regular process or use the actor module. It's a tool for cross platform scripts and not a building block for OTP programs.