Request only the Eio capabilities from env that are actually needed #220
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This implements the recommendation "Passing env" from the Eio documentation:
Among others, this makes Piaf easier to use in applications where only the actually required capabilities are passed around, avoiding the need to define dummy capabilities just to fulfill Piaf's interface.
To provide a specific example, it helps to reduce code like this:
to that:
Some remarks about the implementation:
required_env
(client.ml) andclock
(server.ml) simplify the type definition and casting required to put the Eio capabilities into a record.order_v4v6
has been moved out ofConnection.resolve_host
to make the latter polymorphic in itsenv
parameter. Otherwise, callingConnection.resolve_host
would be more cumbersome, as each call would require an explicit downcast torequired_env
(or a copy of that type inConnection
).resolve_host env ~config ~port hostname =
, but I kept the current style to avoid messing around with the indentation, which would make the PR harder to read.