From 398baadb743d517f7bcaa83b27eb69f6030b07d4 Mon Sep 17 00:00:00 2001 From: nocturn9x Date: Tue, 7 Jul 2020 17:06:20 +0000 Subject: [PATCH] Reverted back one commit. Events not fully working --- giambio/_core.py | 13 ++++++++----- giambio/_layers.py | 8 +------- tests/events.py | 3 +-- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/giambio/_core.py b/giambio/_core.py index 8136178..60187eb 100644 --- a/giambio/_core.py +++ b/giambio/_core.py @@ -102,14 +102,15 @@ class AsyncScheduler: """Checks for ready or expired events and triggers them""" for event, (timeout, _, task) in self.event_waiting.copy().items(): - if event._set: - task._notify = event._notify + if timeout and self.clock() > timeout: + event._timeout_expired = True + event._notify = task._notify = None self.tasks.append(task) self.tasks.append(event.notifier) self.event_waiting.pop(event) - elif timeout and self.clock() > timeout: - event._timeout_expired = True - event._notify = task._notify = None + elif event._set: + event.event_caught = True + task._notify = event._notify self.tasks.append(task) self.tasks.append(event.notifier) self.event_waiting.pop(event) @@ -217,6 +218,8 @@ class AsyncScheduler: """Sets an event""" event.notifier = self.current_task + event._set = True + event._notify = value self.events[event] = value def event_wait(self, event, timeout): diff --git a/giambio/_layers.py b/giambio/_layers.py index b9135f5..ef8c84f 100644 --- a/giambio/_layers.py +++ b/giambio/_layers.py @@ -75,18 +75,12 @@ class Event: """Sets the event, optionally taking a value. This can be used to control tasks' flow by 'sending' commands back and fort""" - self._set = True - self._notify = value await event_set(self, value) async def pause(self, timeout=0): """Waits until the event is set and returns a value""" - msg = await event_wait(self, timeout) - if not self._timeout_expired: - self.event_caught = True - return msg - + return await event_wait(self, timeout) class TimeQueue: """An abstraction layer over a heap queue based on time. This is where diff --git a/tests/events.py b/tests/events.py index fdc59c6..a739415 100644 --- a/tests/events.py +++ b/tests/events.py @@ -8,12 +8,11 @@ async def child(notifier: giambio.Event, timeout: int): else: print("[child] Waiting for events") notification = await notifier.pause(timeout=timeout) - if notifier._timeout_expired: + if not notifier.event_caught: print("[child] Parent was too slow!") else: print(f"[child] Parent said: {notification}") - async def parent(pause: int = 1, child_timeout: int = 0): event = giambio.Event(scheduler) print("[parent] Spawning child task")