Github user tsutsu commented on a diff in the pull request:
https://github.com/apache/couchdb-couch/pull/105#discussion_r40709916
--- Diff: src/couch_stream.erl ---
@@ -51,7 +51,7 @@ open(Fd) ->
open(Fd, []).
open(Fd, Options) ->
- gen_server:start_link(couch_stream, {Fd, self(), Options}, []).
+ gen_server:start_link(couch_stream, {Fd, {self(),
erlang:get(io_priority)}, Options}, []).
--- End diff --
It's a bit of semantic idealism. Since `self()` is already being passed,
and the gen_server could theoretically extract the `io_priority` from the
passed pid() later on (using `erlang:process_info(Pid, dictionary)`, though
it's inefficient and bad form), you could say that self() "contains" the
io_priority in an OOP-theoretic sense. Effectively, the result of using
`erlang:get/1` is *derived data* of `self()`, equivalent to something like the
computed length of a list.
Frequently, you want to pass an object around along with its derived data,
in such a way that its consumers think of the composite as an ADT with the same
functionality as the original object. In a class-based language, you'd do
something silly here with a decorator proxy to enable the object you're passing
to respond to a `get_io_priority` message, but otherwise behave the same. In
Erlang, you'd either use a record (if you want to create a contract on the
shape of the ADT), or simply stick the original data together with its derived
data into a tuple.
...pragmatically, though, that's a bunch of hot air and it's an extra
structure/destructure op and could just as well be eliminated.
(It *would* have more practical value if any intermediate function calls
occurred that had just expected "an owner", where the composite `{OwnerPid,
OwnerPriority}` could "ride through" as an abstract `Owner` and then be
unwrapped only by functions that care. But none do.)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---