macro rrtest(src,val)
quote
r = RemoteChannel($(esc(src))) #Using a `Future` here maybe be better
remotecall_wait(r_i->put!(r_i, $(esc(val))), $(esc(src)), r)
wait(r);
println(fetch(r))
end
end
The wait(r)
should not be required -- fetch
is supposed call wait
when used on a Future
or RemoteChannel
.
But it does seem to be, sometimes.
Changing the @spawnat
to a remotecall
means you can pass in the r
, without that, it gets. I think there are off things with how macro-hygine nests with closures created themself with macros. (@spawnat
) creates closures inside another macro. It is awkaward to reasonabout.
In general I find @spawnat
harder to reason about, than remote_call
.
The reason it needs to be remotecall_wait
is because otherwise, there is no garentee when its contents will run. Which means what is happening to r
is itself unclear. I feel like it should be safe, but it does not seem to be.
I think because the waiting for r
, rather than waiting for the remotecall
that sets r
is never certain to allow that remotecall
to run.
In Conclusion:
- prefer
remotecall
to @spawnat
, particularly in macros, for sake of being easier to reason about.
- Sometimes you have to
wait
for things before fetch
ing them. That is probably a bug
- sometimes waiting for X, when X is to be set by a
remotecall
(or @spawnat
) returning future Y, requires waiting for Y first. Also probably a bug