[ library(notify_ports) | Reference Manual | Alphabetic Index ]
foreachnotification(+BaseName, -Message, +Params, +ReceivePort, -Status, +Goals)
A control construct to iterate over received notifications
- an atom used as the basename for the generated auxiliary predicate
- a variable
- a list of global variables in the iteration body (as in do/2)
- a receiver structure as created by open_receiver
- a variable, will be bound to 'open' or 'closed'
- the goals that will be called for each iteration
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.
This predicate is sensitive to its module context (tool predicate, see @/2).
process_all_messages(ReceivePort, Log) :-
foreachnotification(sample, Message, [Log], ReceivePort, Status, (
( Status = closed ->
receive_notifications / 3