# `EventListener`

digraph inheritance873bd8358e { bgcolor=transparent; rankdir=UD; ratio=compress; size="8.0, 12.0"; "EventListener" [URL="#taurus.core.util.event.EventListener",color=dodgerblue1,fillcolor=white,fontcolor=black,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.5,shape=box,style=rounded,target="_top",tooltip="A class that listens for an event with a specific value"]; }

class EventListener

  A class that listens for an event with a specific value

  Note: Since this class stores for each event value the last timestamp when it occured, it should only be used for events for which the event value domain (possible values) is limited and well known (ex: an enum)

  Import from `taurus.core.util.event` as:

      from taurus.core.util.event import EventListener

  clearEventSet()

    Clears the internal event buffer

  fireEvent(v)

    Notifies that a given event has arrived This function is protected inside with the object’s lock. Do NOT call this function when you have the lock acquired on this object.

    Parameters:

      v (object) – event value

  lock()

    Locks this event listener

  unlock()

    Unlocks this event listener

  waitEvent(val, after=0, equal=True)

    Wait for an event with the given value. You MUST protect this function with this object’s lock before calling this method and always unlock it afterward, of course:

        from taurus.core.util.event import EventListener

        class MyEvtListener(EventListener):
            # Your specific listener code here
            pass

        evt_listener = EventListener()
        try:
            evt_listener.lock()
            t = time.time()
            go()
            evt_listener.waitEvent(Stop, t)
        finally:
            evt_listener.unlock()

    Parameters:

      - val (object) – value to compare

      - after (float) – timestamp. wait for events comming after the given time. default value is 0 meaning any event after Jan 1, 1970

      - equal (bool) – compare for equality. equal=True means an event with the given value, equal=False means any event which as a different value