erlang

What is ref in Erlang?


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 to interpret what role it plays in message interaction.


Solution

  • 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 its size of course). And just like Fred describes in its book, it is great for tagging messages, and recognizing if message we receive is in response to one we just send.