-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75d0ab8
commit 4757c92
Showing
5 changed files
with
39 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,16 @@ | ||
from functools import partial | ||
from typing import Any, Callable, Optional | ||
""" Implements Trace subscriber """ | ||
from broqer import Publisher | ||
from broqer.op import Sink | ||
|
||
from broqer import Publisher, Subscriber | ||
|
||
|
||
class Trace(Subscriber): | ||
def __init__(self, # pylint: disable=keyword-arg-before-vararg | ||
callback: Optional[Callable[..., None]] = None, | ||
*args, unpack=False, **kwargs) -> None: | ||
if callback is None: | ||
self._callback = None # type: Callable | ||
elif args or kwargs: | ||
self._callback = \ | ||
partial(callback, *args, **kwargs) # type: Callable | ||
else: | ||
self._callback = callback # type: Callable | ||
|
||
self._unpack = unpack | ||
|
||
def emit(self, value: Any, who: Publisher): | ||
if self._callback: | ||
if self._unpack: | ||
self._callback(*value) | ||
else: | ||
self._callback(value) | ||
|
||
class Trace(Sink): | ||
""" Trace is a subscriber used for debugging purpose. On subscription | ||
it will use the prepend flag to be the first callback called when the | ||
publisher of interest is emitting. | ||
:param callback: optional function to call | ||
:param /*args: arguments used additionally when calling callback | ||
:param /**kwargs: keyword arguments used when calling callback | ||
:param unpack: value from emits will be unpacked as (*value) | ||
""" | ||
def __call__(self, publisher: Publisher): | ||
return publisher.subscribe(self, prepend=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
""" Module with utilities for broqer """ | ||
from .datatype_check import DTRegistry | ||
|
||
__all__ = ['DTRegistry'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters