What is ref in Erlang?

前端 未结 4 1929
忘掉有多难
忘掉有多难 2021-01-12 08:00

Going through this link

To identify a process,we would be using a Pid. When should a ref be used?

I see this often while message sending/receiving but unable

4条回答
  •  滥情空心
    2021-01-12 08:40

    because ref is unique which can identify received message.

    for example:

    A,B two Actors, A want to known B's age
    
    there are 2 solutions:
    
    Method 1:  A send Msg({age}) to B,then B send result Msg({age,10})
    but,before A receive this Msg,Actor C send Msg{age,20} to A,
    then A got the wrong answer
    
    Method 2: A send Msg({age,Ref}) to B,
    no one knowns the Ref except A and B,
    then A got the right answer from B.
    

提交回复
热议问题