-1
它接縫erlang只向遠程節點發送有趣的引用。當試圖發送閉包時,它顯然會在調用模塊中關閉閉包,並向遠程節點發送一個有趣的參考。這裏的測試:有沒有辦法在erlang中發送一個閉包到遠程節點?
-module(funserver).
-compile(export_all).
loop()->
receive {From, ping} ->
error_logger:info_msg("received ping from ~p~n", [From]),
From ! pong,
loop();
{From, Fun} when is_function(Fun) ->
error_logger:info_msg("executing function ~p received from ~p~n", [Fun, From]),
From ! Fun(),
loop();
M ->
error_logger:error_msg("received ~p, don't know what to do with it", [M])
end.
和測試客戶端節點上:
test_remote_node_can_execute_sent_clojure()->
{ok, ModName, Binary} = compile:file(funserver, [verbose,report_errors,report_warnings, binary]),
{module, ModName} = rpc:call(?other_node, code, load_binary, [ModName, atom_to_list(ModName), Binary]),
Pid = spawn(?other_node, funserver, loop, []),
OutVar = {"token with love from", node()},
Pid ! {self(), fun()-> {OutVar, erlang:node()} end},
receive Result ->
Result = {OutVar, node(Pid)}
after 300 ->
timeout
end.
越來越
Error in process <7162.123.0> on node [email protected] with exit value:
{undef,[{#Fun<tests.1.127565388>,[],[]},
{funserver,loop,0,[{file,"funserver.erl"},{line,12}]}]}
timeout
所以可以Clojure中被髮送到遠程節點?
在[erlang-questions mailing list]中的[this thread](http://erlang.org/pipermail/erlang-questions/2016-September/090046.html)中是否已經對此進行過深入討論? –
[Erlang中的Spawn(Node,Fun)的重點是什麼,如果Node必須具有與客戶端節點相同的模塊可加載的內容,請執行以下操作):(http://stackoverflow.com/questions/39255471/what-is -the-點的spawnnode樂趣-ON-二郎-IF-節點有到有最同月齡) – mpm