pub struct Bridge { /* private fields */ }Expand description
进行中调用、客户端 id 与 channel 的注册表,在多次进程重启之间复用。
内部使用多把互斥锁,任何时刻最多持有其中一把,且锁内不会调用外部回调。
Implementations§
Source§impl Bridge
impl Bridge
Sourcepub async fn call(
&self,
writer: &Writer,
cmd: &str,
args: Payload,
channels: Vec<(String, ChannelSink)>,
opts: CallOptions,
default_timeout: Duration,
) -> Result<Payload>
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。
Sourcepub fn cancel(
&self,
writer: Option<&Writer>,
window: &str,
client_id: &str,
) -> bool
pub fn cancel( &self, writer: Option<&Writer>, window: &str, client_id: &str, ) -> bool
取消 window 窗口中客户端 id 为 client_id 的进行中调用。
等待者立即以 cancelled 失败,不等待 Python 确认;若提供了 writer,还会向 Python 发送
reason: "client" 的 cancel 帧(发送失败被忽略)。返回是否找到并取消了该调用。
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more