pub enum TransitionStatus {
Ready(Result<TransitionOk, TransitionError>),
Pending {
trigger: Trigger,
origin: TaskState,
res_fut: Pin<Box<dyn Future<Output = Result<TransitionOk, TransitionError>> + Send>>,
},
}Expand description
Transition status.
A state transition occurs as a result of a triggering event.
The triggering event is asynchronously handled by a state machine
running on a Context.
Variants§
Ready(Result<TransitionOk, TransitionError>)
Transition result is ready.
Pending
Transition is pending.
Implementations§
Source§impl TransitionStatus
impl TransitionStatus
pub fn is_ready(&self) -> bool
pub fn is_pending(&self) -> bool
Sourcepub fn check(self) -> Result<TransitionStatus, TransitionError>
pub fn check(self) -> Result<TransitionStatus, TransitionError>
Converts the TransitionStatus into a Result.
This function allows getting the TransitionError when
the transition result is ready without awaiting nor blocking.
See also [Self::await_maybe_on_context].
Sourcepub fn block_on_or_add_subtask<O>(
self,
obj: &O,
) -> Result<TransitionOk, TransitionError>
pub fn block_on_or_add_subtask<O>( self, obj: &O, ) -> Result<TransitionOk, TransitionError>
Blocks on this state transition to complete, or adds a subtask if running on a Context.
Notes:
- If you need to execute code after the transition succeeds or fails,
see [
block_on_or_add_subtask_then]. - When running in an
asyncblock within a running transition or task iteration, don’t await for the transition as it would deadlock. UseSelf::checkto make sure the state transition is valid. - When running in an
asyncblock out of a running transition or task iteration, just.awaitnormally. E.g.:
let flush_ok = task.flush_start().await?;This function makes sure the transition completes successfully or
produces an error. It must be used in situations where we don’t know
whether we are running on a Context or not. This is the case for
functions in PadSrc and PadSink as well as the synchronous
functions transitively called from them.
As an example, a PadSrc::src_event function which handles a
FlushStart could call:
return task
.flush_start()
.block_on_or_add_subtask()
.is_ok();If the transition is already complete, the result is returned immediately.
If we are NOT running on a Context, the transition result is awaited
by blocking on current thread and the result is returned.
If we are running on a Context, the transition result is awaited
in a sub task for current Context’s Scheduler task. As a consequence,
the sub task will be awaited in usual Context::drain_sub_tasks
rendezvous, ensuring some kind of synchronization. To avoid deadlocks,
Ok(TransitionOk::NotWaiting { .. }) is immediately returned.
Sourcepub fn block_on_or_add_subtask_then<T, F>(
self,
obj: BorrowedObject<'_, T>,
func: F,
) -> Result<(), ErrorMessage>where
T: IsA<Object> + Send,
F: FnOnce(&T, &Result<TransitionOk, TransitionError>) + Send + 'static,
pub fn block_on_or_add_subtask_then<T, F>(
self,
obj: BorrowedObject<'_, T>,
func: F,
) -> Result<(), ErrorMessage>where
T: IsA<Object> + Send,
F: FnOnce(&T, &Result<TransitionOk, TransitionError>) + Send + 'static,
Blocks on this state transition to complete, or adds a subtask if running on a Context
executing the provided function after the transition succeeds or fails.
Compared to [block_on_or_addsubtask], this function also executes the provieded
func after the transition succeeded or failed. Code following [block_on_or_addsubtask]
can actually be executed before the transition if a subtask was added and the returned
Result might not reflect the actual transition result.
If the transition is already complete, func is executed immediately.
If we are NOT running on a Context, the transition result is awaited
by blocking on current thread and func is executed.
If we are running on a Context, the transition result is awaited
in a sub task for current Context’s Scheduler task and func is executed with
the transition result. In this case, block_on_or_add_subtask_then always
returns Ok(()) since the actual processing is handled asynchronously.
§Example
task
.stop()
.block_on_or_add_subtask_then(self.obj(), |elem, res| {
// Add specific stop code here,
// it will be executed after the transition succeeds or fails
if res.is_ok() {
gst::debug!(CAT, obj = elem, "Stopped");
}
})Trait Implementations§
Source§impl Debug for TransitionStatus
impl Debug for TransitionStatus
Source§impl From<TransitionError> for TransitionStatus
impl From<TransitionError> for TransitionStatus
Source§fn from(err: TransitionError) -> Self
fn from(err: TransitionError) -> Self
Source§impl From<TransitionOk> for TransitionStatus
impl From<TransitionOk> for TransitionStatus
Source§fn from(ok: TransitionOk) -> Self
fn from(ok: TransitionOk) -> Self
Source§impl Future for TransitionStatus
impl Future for TransitionStatus
Source§type Output = Result<TransitionOk, TransitionError>
type Output = Result<TransitionOk, TransitionError>
Auto Trait Implementations§
impl Freeze for TransitionStatus
impl !RefUnwindSafe for TransitionStatus
impl Send for TransitionStatus
impl !Sync for TransitionStatus
impl Unpin for TransitionStatus
impl !UnwindSafe for TransitionStatus
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
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn map<U, F>(self, f: F) -> Map<Self, F>
fn map<U, F>(self, f: F) -> Map<Self, F>
Source§fn map_into<U>(self) -> MapInto<Self, U>
fn map_into<U>(self) -> MapInto<Self, U>
Source§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
f. Read moreSource§fn left_future<B>(self) -> Either<Self, B>
fn left_future<B>(self) -> Either<Self, B>
Source§fn right_future<A>(self) -> Either<A, Self>
fn right_future<A>(self) -> Either<A, Self>
Source§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
Source§fn flatten(self) -> Flatten<Self>
fn flatten(self) -> Flatten<Self>
Source§fn flatten_stream(self) -> FlattenStream<Self>
fn flatten_stream(self) -> FlattenStream<Self>
Source§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
poll will never again be called once it has
completed. This method can be used to turn any Future into a
FusedFuture. Read moreSource§fn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
Source§fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
Source§fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
() on completion and sends
its output to another future on a separate task. Read moreSource§fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
Source§fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
Source§fn unit_error(self) -> UnitError<Self>where
Self: Sized,
fn unit_error(self) -> UnitError<Self>where
Self: Sized,
Future<Output = T> into a
TryFuture<Ok = T, Error = ()>.Source§fn never_error(self) -> NeverError<Self>where
Self: Sized,
fn never_error(self) -> NeverError<Self>where
Self: Sized,
Future<Output = T> into a
TryFuture<Ok = T, Error = Never>.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>
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>
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