from time import sleep

from constant import *
import threading
from waiter import Waiter


class General_observer(threading.Thread, Waiter):
    blackboard = None
    type_observed: str
    independed = True
    last_index = -1

    def __init__(self):
        Waiter.__init__(self)
        threading.Thread.__init__(self)

    def run(self):
        while True:
            if not self.independed:
                self.wait_until((event_print + " " + self.type_observed))
                print("event =", "\"" + (event_print + " " + self.type_observed) + "\"", ", value =",
                      self.blackboard.data[event_second_data][self.type_observed][-1])
            else:
                if len(self.blackboard.data[event_second_data][self.type_observed])-1 > self.last_index:
                    self.last_index += 1
                    print("event =", "woke up", ", value =",
                          self.blackboard.data[event_second_data][self.type_observed][self.last_index])
                else:
                    sleep(0.5)
