Reverted back one commit. Events not fully working

This commit is contained in:
nocturn9x 2020-07-07 17:06:20 +00:00
parent 52ed68f35b
commit 398baadb74
3 changed files with 10 additions and 14 deletions

View File

@ -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):

View File

@ -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

View File

@ -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")