-
Notifications
You must be signed in to change notification settings - Fork 190
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
Suggestion: A better API for RPC
method in Go
#55
Comments
Ah, I'm not really qualified to speak on this--perhaps @benbjohnson might? |
@avinassh It's probably a better API to return the message ID, however, you shouldn't need to do message ID tracking for any of the challenges. I think breaking the API will be significantly more painful than it's worth. For that reason, I'd recommend not implementing the change. |
Continuing from the previous example, I had a background worker check the go func() {
ticker := time.NewTicker(100 * time.Millisecond)
for range ticker.C {
randomMsgId := store.Get()
// randomMsgId is not sent, so resend again
}
}() In the above snippet, msgId is randomly generated, where I kept the state. Without message ids, this is painful. Though I agree that tracking message Ids is not required for any challenges, but when I was solving broadcast challenge, this is how I started working on the solution, it took me a while to realise this is not required at all and later removed the tracking of message ids. So, if someone else were to try the same, I thought we could make it easier.
I am a bit conflicted about this. The way I am using this library is to initiate the go mod once and then implement the challenges. I assume most people might do the same and not update the library when working on a challenge, but I could also be wrong. But when I think from the point of view of future users, this breaking change is okay as it will improve their experiences. |
I used the async
RPC
method in the broadcast challenge. One of the issues I faced was keeping track of the status of calls.I wanted to maintain a list of messages I had sent. If the node had sent the message successfully, I would delete it from the list. If not, I would retry again.
Once I sent a message, I wanted to know if I had gotten any response or if the call had failed. The RPC method adds the auto-incremented message-id, but it does not return to the caller, but the returned status contains the message id. So it was painful to manage this.
Here is what I did:
Sample code:
We can improve this by a great deal by making the RPC method return the msgId of the message it had sent. The change in the go library is minimal, but for the user, the code would be something like the following:
The change in the library:
It is a breaking change, but the developer experience this change provides makes it worth it. Are you open to considering such a change?
The text was updated successfully, but these errors were encountered: