-
Notifications
You must be signed in to change notification settings - Fork 43
/
interface.py
65 lines (50 loc) · 1.58 KB
/
interface.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""ABC"""
import asyncio
from abc import ABC, abstractmethod
class AsyncRunnable(ABC):
"""
Classes that has async work to run
"""
_loop: asyncio.AbstractEventLoop = None
@property
def loop(self) -> asyncio.AbstractEventLoop:
"""the event loop for the async work"""
return self._loop
@loop.setter
def loop(self, new_loop: asyncio.AbstractEventLoop):
self._loop = new_loop
def schedule(self):
"""schedule the async work into background"""
asyncio.ensure_future(self.start(), loop=self.loop)
@abstractmethod
async def start(self):
"""run the async work"""
class LazyLoadable(ABC):
"""
Classes that can be initialized before loaded full data from khl server.
These classes objects usually are constructed by khl.py internal calls.
For example:
`Channel`: we usually construct a channel with a message for convenient,
while we only know the channel's id, so this channel is not `loaded`, until call the `load()`
"""
_loaded: bool
@abstractmethod
async def load(self):
"""
Load full data from khl server
:return: empty
"""
raise NotImplementedError
@property
def loaded(self) -> bool:
"""check if loaded"""
return self._loaded
@loaded.setter
def loaded(self, v: bool):
self._loaded = v
def is_loaded(self) -> bool:
"""DEPRECATED: use ``.loaded`` prop, simpler in code and clearer in semantic
Check if loaded
:return: bool
"""
return self._loaded