mirror of https://github.com/nocturn9x/giambio.git
Reverted back one commit. Events not fully working
This commit is contained in:
parent
52ed68f35b
commit
398baadb74
|
@ -102,14 +102,15 @@ class AsyncScheduler:
|
||||||
"""Checks for ready or expired events and triggers them"""
|
"""Checks for ready or expired events and triggers them"""
|
||||||
|
|
||||||
for event, (timeout, _, task) in self.event_waiting.copy().items():
|
for event, (timeout, _, task) in self.event_waiting.copy().items():
|
||||||
if event._set:
|
if timeout and self.clock() > timeout:
|
||||||
task._notify = event._notify
|
event._timeout_expired = True
|
||||||
|
event._notify = task._notify = None
|
||||||
self.tasks.append(task)
|
self.tasks.append(task)
|
||||||
self.tasks.append(event.notifier)
|
self.tasks.append(event.notifier)
|
||||||
self.event_waiting.pop(event)
|
self.event_waiting.pop(event)
|
||||||
elif timeout and self.clock() > timeout:
|
elif event._set:
|
||||||
event._timeout_expired = True
|
event.event_caught = True
|
||||||
event._notify = task._notify = None
|
task._notify = event._notify
|
||||||
self.tasks.append(task)
|
self.tasks.append(task)
|
||||||
self.tasks.append(event.notifier)
|
self.tasks.append(event.notifier)
|
||||||
self.event_waiting.pop(event)
|
self.event_waiting.pop(event)
|
||||||
|
@ -217,6 +218,8 @@ class AsyncScheduler:
|
||||||
"""Sets an event"""
|
"""Sets an event"""
|
||||||
|
|
||||||
event.notifier = self.current_task
|
event.notifier = self.current_task
|
||||||
|
event._set = True
|
||||||
|
event._notify = value
|
||||||
self.events[event] = value
|
self.events[event] = value
|
||||||
|
|
||||||
def event_wait(self, event, timeout):
|
def event_wait(self, event, timeout):
|
||||||
|
|
|
@ -75,18 +75,12 @@ class Event:
|
||||||
"""Sets the event, optionally taking a value. This can be used
|
"""Sets the event, optionally taking a value. This can be used
|
||||||
to control tasks' flow by 'sending' commands back and fort"""
|
to control tasks' flow by 'sending' commands back and fort"""
|
||||||
|
|
||||||
self._set = True
|
|
||||||
self._notify = value
|
|
||||||
await event_set(self, value)
|
await event_set(self, value)
|
||||||
|
|
||||||
async def pause(self, timeout=0):
|
async def pause(self, timeout=0):
|
||||||
"""Waits until the event is set and returns a value"""
|
"""Waits until the event is set and returns a value"""
|
||||||
|
|
||||||
msg = await event_wait(self, timeout)
|
return await event_wait(self, timeout)
|
||||||
if not self._timeout_expired:
|
|
||||||
self.event_caught = True
|
|
||||||
return msg
|
|
||||||
|
|
||||||
|
|
||||||
class TimeQueue:
|
class TimeQueue:
|
||||||
"""An abstraction layer over a heap queue based on time. This is where
|
"""An abstraction layer over a heap queue based on time. This is where
|
||||||
|
|
|
@ -8,12 +8,11 @@ async def child(notifier: giambio.Event, timeout: int):
|
||||||
else:
|
else:
|
||||||
print("[child] Waiting for events")
|
print("[child] Waiting for events")
|
||||||
notification = await notifier.pause(timeout=timeout)
|
notification = await notifier.pause(timeout=timeout)
|
||||||
if notifier._timeout_expired:
|
if not notifier.event_caught:
|
||||||
print("[child] Parent was too slow!")
|
print("[child] Parent was too slow!")
|
||||||
else:
|
else:
|
||||||
print(f"[child] Parent said: {notification}")
|
print(f"[child] Parent said: {notification}")
|
||||||
|
|
||||||
|
|
||||||
async def parent(pause: int = 1, child_timeout: int = 0):
|
async def parent(pause: int = 1, child_timeout: int = 0):
|
||||||
event = giambio.Event(scheduler)
|
event = giambio.Event(scheduler)
|
||||||
print("[parent] Spawning child task")
|
print("[parent] Spawning child task")
|
||||||
|
|
Loading…
Reference in New Issue