pub struct AsyncBridge;
Expand description
异步/同步边界处理工具
Implementations§
Source§impl AsyncBridge
impl AsyncBridge
Sourcepub fn run_async_in_sync<F, T>(future: F) -> ForgeResult<T>
pub fn run_async_in_sync<F, T>(future: F) -> ForgeResult<T>
在同步上下文中安全地执行异步操作
此方法会检查当前是否在 Tokio 运行时中:
- 如果在运行时中,使用 spawn_blocking 避免阻塞
- 如果不在运行时中,创建临时运行时执行
§警告
此方法应该谨慎使用,主要用于:
- Drop 实现
- 同步的 FFI 边界
- 测试代码
Sourcepub fn run_async_in_sync_with_timeout<F, T>(
future: F,
timeout: Duration,
) -> ForgeResult<T>
pub fn run_async_in_sync_with_timeout<F, T>( future: F, timeout: Duration, ) -> ForgeResult<T>
在同步上下文中安全地执行异步操作(带超时)
Sourcepub fn is_in_async_context() -> bool
pub fn is_in_async_context() -> bool
检查当前是否在异步上下文中
Sourcepub async fn run_blocking_in_async<F, T>(blocking_op: F) -> ForgeResult<T>
pub async fn run_blocking_in_async<F, T>(blocking_op: F) -> ForgeResult<T>
安全地在异步上下文中执行可能阻塞的操作
此方法会将阻塞操作移到专用的阻塞线程池中执行
Auto Trait Implementations§
impl Freeze for AsyncBridge
impl RefUnwindSafe for AsyncBridge
impl Send for AsyncBridge
impl Sync for AsyncBridge
impl Unpin for AsyncBridge
impl UnwindSafe for AsyncBridge
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more