Make the `Context` a dataclass
parent
b403a20f32
commit
251ee177fa
|
@ -1,6 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Inter-process comms abstractions
|
Inter-process comms abstractions
|
||||||
"""
|
"""
|
||||||
|
from dataclasses import dataclass
|
||||||
import typing
|
import typing
|
||||||
from typing import Any, Tuple, Optional
|
from typing import Any, Tuple, Optional
|
||||||
|
|
||||||
|
@ -205,6 +206,7 @@ class Channel:
|
||||||
return self.squeue.connected() if self.squeue else False
|
return self.squeue.connected() if self.squeue else False
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
class Context:
|
class Context:
|
||||||
"""An IAC (inter-actor communication) context.
|
"""An IAC (inter-actor communication) context.
|
||||||
|
|
||||||
|
@ -212,13 +214,12 @@ class Context:
|
||||||
actors. A unique context is created on the receiving end for every request
|
actors. A unique context is created on the receiving end for every request
|
||||||
to a remote actor.
|
to a remote actor.
|
||||||
"""
|
"""
|
||||||
def __init__(
|
chan: Channel
|
||||||
self,
|
cid: str
|
||||||
channel: Channel,
|
|
||||||
command_id: str,
|
# TODO: we should probably attach the actor-task
|
||||||
) -> None:
|
# cancel scope here now that trio is exposing it
|
||||||
self.chan: Channel = channel
|
# as a public object
|
||||||
self.cid: str = command_id
|
|
||||||
|
|
||||||
async def send_yield(self, data: Any) -> None:
|
async def send_yield(self, data: Any) -> None:
|
||||||
await self.chan.send({'yield': data, 'cid': self.cid})
|
await self.chan.send({'yield': data, 'cid': self.cid})
|
||||||
|
|
Loading…
Reference in New Issue