What is ref in Erlang?

前端 未结 4 1907
忘掉有多难
忘掉有多难 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:46

    To quote documentation

    A reference is a term which is unique in an Erlang runtime system, created by calling make_ref/0.

    This means that this is special data type, it's not an integer, not a list, and not a binary. Especially with unique prosperity. It's designed mostly to recognize some places in code. make_ref(), no matter where it is called, will return new value (in boundaries of it's size of course). And just like Fred describes in it's book, it is great for tagging messages, and recognizing if message we receive is in response to one we just send.

提交回复
热议问题