-
Notifications
You must be signed in to change notification settings - Fork 205
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
Haskell ledger bindings #1460
Haskell ledger bindings #1460
Conversation
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.
Instead of getting a callback ClientCall -> IO ()
which is called once, should you instead be returning a pair of a stream and a ClientCall?
@@ -258,12 +258,14 @@ clientReader :: Client | |||
-> TimeoutSeconds | |||
-> ByteString -- ^ The body of the request | |||
-> MetadataMap -- ^ Metadata to send with the request | |||
-> (ClientCall -> IO ()) |
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.
Is this the right API? Should you be returning the ClientCall?
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.
What do you suggest?
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.
Maybe we make a new type which only allow cancel to be called.
But returning the LL.ClientCall is more general.
And the user only gets the ClientCall if they explicitly ask for it.
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.
Returning the pair of ClientCall and the value would have been my approach, if it fits. If the only sensible thing you can do is cancel it then return a pair of IO ()
(the cancel function) and the value. FWIW at a previous company I defined newtype Cancel = Cancel (IO ())
and it was quite a successful abstraction.
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.
We can't return a pair because the interface is set up in a with-resource style, the ClientCall
value being obtained from withClientCall
.
I was about to introduce the Cancel
abstraction you suggested, when I noticed that ClientCall
and clientCallCancel
were already exposed in the HighLevel
interface. (The only thing missing was how to obtain a ClientCall
value.)
Since the type of ClientCall
is abstract, the only thing to be done is call clientCallCancel
on it. And so it seems to fulfill the role of the suggested newtype.
So I the end, didn't add it.
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.
Fair enough on all points.
Haskell ledger bindings, WIP