-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use a_sync.SmartProcessingQueue instead of semaphores (#183)
- Loading branch information
1 parent
320af2a
commit 6ff6e4a
Showing
12 changed files
with
117 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
# type: ignore [attr-defined] | ||
import logging | ||
|
||
import a_sync | ||
|
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
from msgspec import Raw, json | ||
|
||
from dank_mids.types import (Any, Callable, JSONRPCBatchResponseRaw, List, PartialResponse, | ||
RawResponse, Union, nested_dict_of_stuff, _encode_hook) | ||
|
||
|
||
decode_raw = lambda data: RawResponse(json.decode(data, type=Raw)) | ||
"""Decode json-encoded bytes into a `msgspec.Raw` object.""" | ||
|
||
decode_nested_dict = lambda data: json.decode(data, type=nested_dict_of_stuff) | ||
"""Decode json-encoded bytes into a nested dictionary.""" | ||
|
||
def decode_jsonrpc_batch(data: bytes) -> Union[PartialResponse, List[RawResponse]]: | ||
"""Decode json-encoded bytes into a list of response structs, or a single error response struct if applicable.""" | ||
decoded = json.decode(data, type=JSONRPCBatchResponseRaw) | ||
return decoded if isinstance(decoded, PartialResponse) else _map_raw(decoded) | ||
|
||
_map_raw: Callable[[List[Raw]], List[RawResponse]] = lambda decoded: list(map(RawResponse, decoded)) | ||
"""Converts a list of `msgspec.Raw` objects into a list of `RawResponse` objects.""" | ||
|
||
def encode(obj: Any) -> bytes: | ||
"""Encode an object to json-encoded bytes.""" | ||
return json.encode(obj, enc_hook=_encode_hook) |
This file was deleted.
Oops, something went wrong.
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