Skip to main content

Bridge

Struct Bridge 

Source
pub struct Bridge { /* private fields */ }
Expand description

进行中调用、客户端 id 与 channel 的注册表,在多次进程重启之间复用。

内部使用多把互斥锁,任何时刻最多持有其中一把,且锁内不会调用外部回调。

Implementations§

Source§

impl Bridge

Source

pub fn new() -> Self

创建空的注册表。

Source

pub async fn call( &self, writer: &Writer, cmd: &str, args: Payload, channels: Vec<(String, ChannelSink)>, opts: CallOptions, default_timeout: Duration, ) -> Result<Payload>

通过 writer 发送一次命令调用,并等待 Python 的响应。

channels 中的每个回调会分配一个新的 channel id,随请求以“参数名 → channel id”发送, 调用结束后即注销。超时时间为 opts.timeout(上限为 default_timeout 的 MAX_TIMEOUT_FACTOR 倍)或 default_timeout;超时后会向 Python 发送 reason: "timeout" 的 cancel 帧。

§Errors
  • invalid_args:同一窗口内该客户端调用 id 仍在进行中;
  • frame_too_large / runtime_unavailable:请求帧无法发送(见 Writer::send);
  • timeout:超过超时时间;
  • cancelled:被 Bridge::cancel 取消;
  • runtime_exited 等:被 Bridge::fail_all 以指定错误码终止;
  • Python 返回的错误(如 command_not_found、invalid_args、internal 或自定义错误码), 以及响应载荷不一致时的 internal。
Source

pub fn cancel( &self, writer: Option<&Writer>, window: &str, client_id: &str, ) -> bool

取消 window 窗口中客户端 id 为 client_id 的进行中调用。

等待者立即以 cancelled 失败,不等待 Python 确认;若提供了 writer,还会向 Python 发送 reason: "client" 的 cancel 帧(发送失败被忽略)。返回是否找到并取消了该调用。

Source

pub fn handle(&self, frame: Frame, sink: &dyn EventSink)

处理一帧来自 Python 的消息:完成对应调用、转发事件或投递 channel 数据。

未知调用 id 或 channel 的帧被静默丢弃;载荷不一致或方向错误的帧记录警告后丢弃, 不影响连接。

Source

pub fn fail_all(&self, code: &str, message: &str)

以给定错误码终止所有进行中的调用,并清空客户端 id 与 channel 注册表。

在 Python 进程退出、停止或启动失败时调用。

Trait Implementations§

Source§

impl Default for Bridge

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !Freeze for Bridge

§

impl Forget for Bridge

§

impl Move for Bridge

§

impl RefUnwindSafe for Bridge

§

impl Send for Bridge

§

impl Sync for Bridge

§

impl Unpin for Bridge

§

impl UnsafeUnpin for Bridge

§

impl UnwindSafe for Bridge

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.