-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdirect.py
More file actions
61 lines (49 loc) · 1.76 KB
/
direct.py
File metadata and controls
61 lines (49 loc) · 1.76 KB
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
import threading
import typing
from .base import DispatcherBaseClass
class DirectDispatcher(DispatcherBaseClass):
"""The DirectDispatcher executes the provided callback immediately"""
def __init__(
self,
callback: typing.Callable[[list[typing.Any], str], None],
object_types: list[str],
termination_trigger: threading.Event,
**_,
) -> None:
"""Initialise a new DirectDispatcher instance
Parameters
----------
callback : typing.Callable[[list[typing.Any], str], None]
callback to be executed on each item provided
object_types : list[str]
categories, this is mainly used for creation of queues in a QueueDispatcher
termination_trigger : Event
event which triggers termination of the dispatcher
"""
super().__init__(
callback=callback,
object_types=object_types,
termination_trigger=termination_trigger,
)
def add_item(self, item: typing.Any, object_type: str, *_, **__) -> None:
"""Execute callback on the given item"""
self._callback([item], object_type)
def run(self) -> None:
"""Run does not execute anything in this context"""
pass
def start(self) -> None:
"""Start does not execute anything in this context"""
pass
def join(self) -> None:
"""Join does not execute anything in this context"""
pass
def purge(self) -> None:
"""Purge does not execute anything in this context"""
pass
def is_alive(self) -> bool:
"""As unthreaded, state as not alive always"""
return False
@property
def empty(self) -> bool:
"""No queue so always empty"""
return True