Skip to content

Commit

Permalink
move fallback fetch(::Any) to Base (#30961)
Browse files Browse the repository at this point in the history
fixes an item from #30945
  • Loading branch information
JeffBezanson authored Feb 5, 2019
1 parent f759bc3 commit 2b84993
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions base/task.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ function wait(t::Task)
end
end

fetch(@nospecialize x) = x

"""
fetch(t::Task)
Expand Down
3 changes: 2 additions & 1 deletion stdlib/Distributed/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Distributed.pmap
Distributed.RemoteException
Distributed.Future
Distributed.RemoteChannel
Distributed.fetch(::Any)
Distributed.fetch(::Future)
Distributed.fetch(::RemoteChannel)
Distributed.remotecall(::Any, ::Integer, ::Any...)
Distributed.remotecall_wait(::Any, ::Integer, ::Any...)
Distributed.remotecall_fetch(::Any, ::Integer, ::Any...)
Expand Down
23 changes: 11 additions & 12 deletions stdlib/Distributed/src/remotecall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,13 @@ Wait for a value to become available on the specified [`RemoteChannel`](@ref).
"""
wait(r::RemoteChannel, args...) = (call_on_owner(wait_ref, r, myid(), args...); r)

"""
fetch(x::Future)
Wait for and get the value of a [`Future`](@ref). The fetched value is cached locally.
Further calls to `fetch` on the same reference return the cached value. If the remote value
is an exception, throws a [`RemoteException`](@ref) which captures the remote exception and backtrace.
"""
function fetch(r::Future)
r.v !== nothing && return something(r.v)
v = call_on_owner(fetch_ref, r)
Expand All @@ -515,22 +522,14 @@ function fetch(r::Future)
end

fetch_ref(rid, args...) = fetch(lookup_ref(rid).c, args...)
fetch(r::RemoteChannel, args...) = call_on_owner(fetch_ref, r, args...)

"""
fetch(x)
fetch(c::RemoteChannel)
Waits and fetches a value from `x` depending on the type of `x`:
* [`Future`](@ref): Wait for and get the value of a `Future`. The fetched value is cached locally.
Further calls to `fetch` on the same reference return the cached value. If the remote value
is an exception, throws a [`RemoteException`](@ref) which captures the remote exception and backtrace.
* [`RemoteChannel`](@ref): Wait for and get the value of a remote reference. Exceptions raised are
same as for a `Future` .
Does not remove the item fetched.
Wait for and get a value from a [`RemoteChannel`](@ref). Exceptions raised are the
same as for a `Future`. Does not remove the item fetched.
"""
fetch(@nospecialize x) = x
fetch(r::RemoteChannel, args...) = call_on_owner(fetch_ref, r, args...)

isready(rv::RemoteValue, args...) = isready(rv.c, args...)

Expand Down

0 comments on commit 2b84993

Please sign in to comment.