-
Notifications
You must be signed in to change notification settings - Fork 225
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
feat: add result-returning send
variants to Env
and OwnedEnv
#563
Conversation
Adds: - ``` Env::{ send_returning_i32, send_returning_i32_result, send_returning_result, send_returning_bool } ``` - ``` OwnedEnv::{ send_and_clear_returning_i32, send_and_clear_returning_i32_result, send_and_clear_returning_result, send_and_clear_returning_bool } ```
I think only the I'm not quite sure, where you would see an improvement with this, though. The two documented error states (sender process is not alive or receiver process is not alive) are only checked at the time of sending, it could still be that the receiver process dies before processing the message. I'm also not sure whether the first case (sender process died) is even possible with our interface, at least not for owned envs. It is definitely wrong to just blindly |
For sure, the majority of cases that are using Regarding I'm happy with a |
Thinking a bit more about this, I'd propose to change the signature to |
I think whether to use a
But maybe we should encourage users to read the documentation for that function, as the boolean fuses two distinct error cases. That is useful information when debugging why an expected message might not turn up at a receiver. When using a In any case, I don't have a strong opinion on this one. I can see benefits in both. As |
Certainly a I have a slight preference for this route over Who knows, maybe somewhere down the line OTP would accept an |
I have a strong preference for |
An advantage of using a Result might be that the user is actually warned if they ignore the return value. It forces the user to deal with the possibility of error, even if they just end up doing |
I have incorporated the results of this discussion (going with returning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Looks great, cheers! |
Env::send()
andOwnedEnv::send_and_clear()
should ideally not elide the return value ofenif_send
.Included are several variants, all of which provide exactly the same information, given the current NIF API.
My take is that the preferred solution would be to pick one and resignature
send()
, but we could also keep some/all of the variants provided instead.In all cases, resignature would not a breaking API change, but will generate warnings for the
_result
variants. The_i32
and_bool
variants are less idiomatic, but do not suffer from this issue. Nonetheless, my thinking is that an unhandledResult
warning is ideal in this case, as it makes users aware of the fact that they are currently discarding information without breaking the build.The naming is intentionally clunky, and if we decide to keep one or more of the
send_*()
variants rather than resignaturesend()
, I'm happy to redraft with nicer names. Additional/modified tests will also follow that decision.