-
Notifications
You must be signed in to change notification settings - Fork 0
/
NotifyEvent.py
38 lines (31 loc) · 849 Bytes
/
NotifyEvent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import asyncio
class NotifyEvent(asyncio.Event):
event = asyncio.Event()
event.set()
def set(self, name=None):
self._name = name
if self.is_set():
self.clear()
if NotifyEvent.event.is_set():
NotifyEvent.event.clear()
super().set()
async def wait(self):
await self.event.wait()
await super().wait()
return self._name
def clear(self):
NotifyEvent.event.set()
NotifyEvent.event.clear()
super().clear()
NotifyEvent.event.clear()
async def task(name, notify):
my, other = 0, 0
while True:
dest = await notify.wait()
if dest is None:
break
elif dest == name:
my += 1
print(name, ": ", my, " / ", other, sep="")
else:
other += 1