..
   This file is part of Logtalk <https://logtalk.org/>
   SPDX-FileCopyrightText: 1998-2026 Paulo Moura <pmoura@logtalk.org>
   SPDX-License-Identifier: Apache-2.0

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.


.. rst-class:: align-right

**built-in method**

.. index:: pair: after/3; Built-in method
.. _methods_after_3:

``after/3``
===========

Description
-----------

::

   after(Object, Message, Sender)

User-defined method for handling :ref:`after events <events_definitions>`.
This method is declared in the :ref:`monitoring <apis:monitoring/0>` built-in
protocol as a public predicate and is automatically called by the runtime for
messages sent using the :ref:`control_send_to_object_2` control construct
from within objects compiled with the :ref:`events <flag_events>` flag set
to ``allow``.

Note that you can make this predicate scope protected or private by using,
respectively, :ref:`protected or private implementation <inheritance_scope>`
of the ``monitoring`` protocol.

Modes and number of proofs
--------------------------

::

   after(?object_identifier, ?callable, ?object_identifier) - zero_or_more

Errors
------

(none)

Examples
--------

::

   :- object(...,
       implements(monitoring),
       ...).

       % write a log message when a message is successful:
       after(Object, Message, Sender) :-
           writeq(Object), write('::'), writeq(Message),
           write(' from '), writeq(Sender), nl.

.. seealso::

   :ref:`methods_before_3`,
   :ref:`predicates_abolish_events_5`,
   :ref:`predicates_current_event_5`,
   :ref:`predicates_define_events_5`
