What kind of types can be sent on an Erlang message?

后端 未结 3 2017
清酒与你
清酒与你 2020-12-29 15:29

Mainly I want to know if I can send a function in a message in a distributed Erlang setup.

On Machine 1:

F1 = Fun(         


        
3条回答
  •  Happy的楠姐
    2020-12-29 15:48

    As for anonymous functions, it seems they can be sent and work as expected.

    t1@localhost:

    (t1@localhost)7> register(shell, self()).
    true
    (t1@localhost)10> A = me, receive Fun when is_function(Fun) -> Fun(A) end.
    hello me you
    ok
    

    t2@localhost:

    (t2@localhost)11> B = you.
    you
    (t2@localhost)12> Fn2 = fun (A) -> io:format("hello ~p ~p~n", [A, B]) end.
    #Fun
    (t2@localhost)13> {shell, 't1@localhost'} ! Fn2.
    

    I am adding coverage logic to an app built on riak-core, and the merge of results gathered can be tricky if anonymous functions cannot be used in messages.

    Also check out riak_kv/src/riak_kv_coverage_filter.erl

    riak_kv might be using it to filter result, I guess.

提交回复
热议问题