erlang - How does receive block work? -


i had simple question , can't seem find answer it. question if have function recording state (recursive) , send multiple messages it, keep going through receive block until no longer has messages in "mailbox"?

state(fridge) ->     receive         pat1 ->             io:format("ok"),             state(s);         pat2 ->             io:format("not ok"),             state(s)     end. 

so if i'd send process 3 messages (pat1, pat2, pat1) using "!" , not able go loop before receiving messages still print out following?

1> "ok" 2> "not ok" 3> "ok" 

sorry if isn't put, simplifying question might make hard picture asking.

your question isn't clear seem asking whether process receive 3 messages if they're sent before target process has called receive — if that's question, answer yes. when send message process, goes process's message queue until process calls receive remove message queue , deal it.

if call erlang:process_info(pid, messages) pid receiver's process id, can see messages in queue. might try erlang shell.

as extreme example of message queueing, under heavy load conditions can source of out-of-memory problems if receiver can't keep fast sender. under these conditions, receiver's message queue might grow without bound until system runs out of memory.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -