From 251ee177fae833e0963d7c55911a8d02874d9f53 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 20 Jan 2019 21:47:08 -0500 Subject: [PATCH] Make the `Context` a dataclass --- tractor/_ipc.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tractor/_ipc.py b/tractor/_ipc.py index 2da8e12..0477740 100644 --- a/tractor/_ipc.py +++ b/tractor/_ipc.py @@ -1,6 +1,7 @@ """ Inter-process comms abstractions """ +from dataclasses import dataclass import typing from typing import Any, Tuple, Optional @@ -205,6 +206,7 @@ class Channel: return self.squeue.connected() if self.squeue else False +@dataclass(frozen=True) class 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 to a remote actor. """ - def __init__( - self, - channel: Channel, - command_id: str, - ) -> None: - self.chan: Channel = channel - self.cid: str = command_id + chan: Channel + cid: str + + # TODO: we should probably attach the actor-task + # cancel scope here now that trio is exposing it + # as a public object async def send_yield(self, data: Any) -> None: await self.chan.send({'yield': data, 'cid': self.cid})