@@ -749,8 +749,9 @@ function remotecall_wait(f, w::Worker, args...)
749749 rv. waitingfor = w. id
750750 rr = RemoteRef (w)
751751 send_msg (w, CallWaitMsg (f, args, rr2id (rr), prid))
752- wait (rv)
752+ v = fetch (rv. c )
753753 delete! (PGRP. refs, prid)
754+ isa (v, RemoteException) && throw (v)
754755 rr
755756end
756757
@@ -783,8 +784,18 @@ function call_on_owner(f, rr::RemoteRef, args...)
783784 end
784785end
785786
786- wait_ref (rid, args... ) = (wait (lookup_ref (rid). c, args... ); nothing )
787- wait (r:: RemoteRef , args... ) = (call_on_owner (wait_ref, r, args... ); r)
787+ function wait_ref (rid, callee, args... )
788+ v = fetch_ref (rid, args... )
789+ if isa (v, RemoteException)
790+ if myid () == callee
791+ throw (v)
792+ else
793+ return v
794+ end
795+ end
796+ nothing
797+ end
798+ wait (r:: RemoteRef , args... ) = (call_on_owner (wait_ref, r, myid (), args... ); r)
788799
789800fetch_ref (rid, args... ) = fetch (lookup_ref (rid). c, args... )
790801fetch (r:: RemoteRef , args... ) = call_on_owner (fetch_ref, r, args... )
@@ -796,19 +807,23 @@ put_ref(rid, args...) = put!(lookup_ref(rid), args...)
796807put! (rr:: RemoteRef , args... ) = (call_on_owner (put_ref, rr, args... ); rr)
797808
798809take! (rv:: RemoteValue , args... ) = take! (rv. c, args... )
799- take_ref (rid, args... ) = take! (lookup_ref (rid), args... )
800- take! (rr:: RemoteRef , args... ) = call_on_owner (take_ref, rr, args... )
810+ function take_ref (rid, callee, args... )
811+ v= take! (lookup_ref (rid), args... )
812+ isa (v, RemoteException) && (myid () == callee) && throw (v)
813+ v
814+ end
815+ take! (rr:: RemoteRef , args... ) = call_on_owner (take_ref, rr, myid (), args... )
801816
802817close_ref (rid) = (close (lookup_ref (rid). c); nothing )
803818close (rr:: RemoteRef ) = call_on_owner (close_ref, rr)
804819
805820
806821function deliver_result (sock:: IO , msg, oid, value)
807822 # print("$(myid()) sending result $oid\n")
808- if is (msg,:call_fetch )
823+ if is (msg,:call_fetch ) || isa (value, RemoteException)
809824 val = value
810825 else
811- val = oid
826+ val = :OK
812827 end
813828 try
814829 send_msg_now (sock, ResultMsg (oid, val))
903918function handle_msg (msg:: CallWaitMsg , r_stream, w_stream)
904919 @schedule begin
905920 rv = schedule_call (msg. response_oid, ()-> msg. f (msg. args... ))
906- deliver_result (w_stream, :call_wait , msg. notify_oid, wait (rv))
921+ deliver_result (w_stream, :call_wait , msg. notify_oid, fetch (rv. c ))
907922 end
908923end
909924
0 commit comments