
foreachnotification(+BaseName, -Message, +Params, +ReceivePort, -Status, +Goals)

   A control construct to iterate over received notifications

Arguments
   BaseName            an atom used as the basename for the generated auxiliary predicate
   Message             a variable
   Params              a list of global variables in the iteration body (as in do/2)
   ReceivePort         a receiver structure as created by open_receiver
   Status              a variable, will be bound to 'open' or 'closed'
   Goals               the goals that will be called for each iteration

Type
   library(notify_ports)

Description

    This is a control construct iterating over the currently available
    messages on the given receive port. The purpose is to process the
    received messages one by one without the need to create an auxiliary
    list of received messages. The iteration terminates when there are
    (currently) no more message on the receive port.
    
    When the iteration terminates, the Status argument indicates whether
    the associated sender is still open ('open') or has been closed
    ('closed'). If closed, no more messages will arrive on this receive
    port in the future.
    

    

Modules
   This predicate is sensitive to its module context (tool predicate, see @/2).

Examples
   
	process_all_messages(ReceivePort, Log) :-
	    foreachnotification(sample, Message, [Log], ReceivePort, Status, (
		writeln(Log, received(Message)),
		do_something(Message)
	    )),
	    ( Status = closed ->
		writeln(Log, end_of_messages)
	    ;
		writeln(Log, more_coming)
	    ).
    

See Also
   receive_notifications / 3
