-
Notifications
You must be signed in to change notification settings - Fork 5
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
Rework API #1
Rework API #1
Conversation
@josevalim you were right, shaved off a lot of code by using your proposed API. One last question from me: do we want to be able to remove ownerships? We could do that by having the callback in |
@josevalim this is ready for review. This API is fantastic IMO, and definitely works on Mox 🙃 I have the Mox PR in dashbitco/mox#148. Right now, we're basically keeping |
Gets the owner of `key` through one of the `callers`. | ||
|
||
If one of the `callers` owns `key` or is allowed access to `key`, | ||
then this function returns `{:ok, {owner_pid, metadata}}` where `metadata` is the |
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.
{:ok, {owner_pid, metadata}}
I don't think it's returned anymore and the typespecs say so. Which I think is a shame because we could always find metadata from any caller with just one call instead of now two calls:
defmodule Req.Test do
@ownership Req.Ownership
def stub(name) do
case NimbleOwnership.fetch_owner(@ownership, callers(), name) do
{:ok, owner} when is_pid(owner) ->
%{^name => value} = NimbleOwnership.get_owned(@ownership, owner)
value
:error ->
raise "cannot find stub #{inspect(name)} in process #{inspect(self())}"
end
end
def stub(name, value) do
NimbleOwnership.get_and_update(@ownership, self(), name, fn _ -> {:ok, value} end)
end
defp callers do
[self() | Process.get(:"$callers") || []]
end
end
I think 2 calls are still OK but thought I'd mention this anyway.
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.
@wojtekmach I lost 90% of context on this already ahah. We could add fetch_owner_with_metadata/3
, but do you have time to take a look at whether that's viable and if it would help in Mox too?
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.
Yup I’ll look into it soon!
WIP API discussed with @josevalim.