Trait gio::prelude::AsyncInitableExt
source · pub trait AsyncInitableExt: 'static {
// Required methods
unsafe fn init_async<P: FnOnce(Result<(), Error>) + 'static>(
&self,
io_priority: Priority,
cancellable: Option<&impl IsA<Cancellable>>,
callback: P
);
unsafe fn init_future(
&self,
io_priority: Priority
) -> Pin<Box_<dyn Future<Output = Result<(), Error>> + 'static>>;
}
Expand description
Required Methods§
sourceunsafe fn init_async<P: FnOnce(Result<(), Error>) + 'static>(
&self,
io_priority: Priority,
cancellable: Option<&impl IsA<Cancellable>>,
callback: P
)
unsafe fn init_async<P: FnOnce(Result<(), Error>) + 'static>( &self, io_priority: Priority, cancellable: Option<&impl IsA<Cancellable>>, callback: P )
Starts asynchronous initialization of the object implementing the
interface. This must be done before any real use of the object after
initial construction. If the object also implements Initable
you can
optionally call InitableExt::init()
instead.
This method is intended for language bindings. If writing in C,
AsyncInitable::new_async()
should typically be used instead.
When the initialization is finished, callback
will be called. You can
then call g_async_initable_init_finish()
to get the result of the
initialization.
Implementations may also support cancellation. If cancellable
is not
None
, then initialization can be cancelled by triggering the cancellable
object from another thread. If the operation was cancelled, the error
IOErrorEnum::Cancelled
will be returned. If cancellable
is not None
, and
the object doesn’t support cancellable initialization, the error
IOErrorEnum::NotSupported
will be returned.
As with Initable
, if the object is not initialized, or initialization
returns with an error, then all operations on the object except
g_object_ref()
and g_object_unref()
are considered to be invalid, and
have undefined behaviour. They will often fail with g_critical()
or
g_warning()
, but this must not be relied on.
Callers should not assume that a class which implements AsyncInitable
can
be initialized multiple times; for more information, see InitableExt::init()
.
If a class explicitly supports being initialized multiple times,
implementation requires yielding all subsequent calls to init_async()
on the
results of the first call.
For classes that also support the Initable
interface, the default
implementation of this method will run the InitableExt::init()
function
in a thread, so if you want to support asynchronous initialization via
threads, just implement the AsyncInitable
interface without overriding
any interface methods.
io_priority
the [I/O priority][io-priority] of the operation
cancellable
optional Cancellable
object, None
to ignore.
callback
a GAsyncReadyCallback
to call when the request is satisfied