-
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.
sistana: new receiver, endpoint determine
- Loading branch information
1 parent
4112acc
commit 9cdfd3b
Showing
9 changed files
with
87 additions
and
75 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
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 |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
from .track import Preset | ||
|
||
if TYPE_CHECKING: | ||
from .fragment import _Fragment | ||
pass | ||
|
||
|
||
@dataclass | ||
|
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,43 +1,37 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from typing import TYPE_CHECKING, Any, Generic, TypeVar | ||
from typing import Any, Callable, Generic, TypeVar | ||
|
||
if TYPE_CHECKING: | ||
from .snapshot import AnalyzeSnapshot | ||
from ..utils.misc import Some | ||
|
||
T = TypeVar("T") | ||
|
||
T = TypeVar("T") | ||
|
||
@dataclass | ||
class Rx(Generic[T]): | ||
name: str | ||
RxGet = Callable[[], Some[T]] | ||
RxPut = Callable[[T], None] | ||
|
||
def receive(self, snapshot: AnalyzeSnapshot, data: T) -> None: | ||
snapshot.cache[self.name] = data | ||
|
||
def load(self, snapshot: AnalyzeSnapshot): | ||
return snapshot.cache[self.name] | ||
class Rx(Generic[T]): | ||
def receive(self, get: RxGet[Any], put: RxPut[Any], data: T) -> None: | ||
if get() is None: | ||
put(data) | ||
|
||
|
||
@dataclass | ||
class CountRx(Rx[Any]): | ||
def receive(self, snapshot: AnalyzeSnapshot, data: Any) -> None: | ||
snapshot.cache[self.name] = snapshot.cache.get(self.name, 0) + 1 | ||
def receive(self, get: RxGet[int], put: RxPut[int], data: Any) -> None: | ||
v = get() | ||
|
||
def load(self, snapshot: AnalyzeSnapshot): | ||
return snapshot.cache.get(self.name, 0) | ||
if v is None: | ||
put(1) | ||
else: | ||
put(v.value + 1) | ||
|
||
|
||
@dataclass | ||
class AccumRx(Rx[T]): | ||
def receive(self, snapshot: AnalyzeSnapshot, data: str) -> None: | ||
if self.name in snapshot.cache: | ||
target = snapshot.cache[self.name] | ||
else: | ||
target = snapshot.cache[self.name] = [] | ||
def receive(self, get: RxGet[list[T]], put: RxPut[list[T]], data: T) -> None: | ||
v = get() | ||
|
||
target.append(data) | ||
|
||
def load(self, snapshot: AnalyzeSnapshot): | ||
return snapshot.cache.get(self.name) or [] | ||
if v is None: | ||
put([data]) | ||
else: | ||
put([*v.value, data]) |
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