wait_shutdown


Description:

[ Version ( since = "1.42" ) ]
public async bool wait_shutdown (bool integrate_maincontext, Cancellable? cancellable) throws Error

The way to stop Client is by unrefing it.

That will cancel all internally pending async operations. However, as async operations in NMClient use GTask, hence they cannot complete right away. Instead, their (internal) result callback still needs to be dispatched by iterating the client's main context.

You thus cannot stop iterating the client's main context until everything is wrapped up. get_context_busy_watcher helps to watch how long that will be.

This function automates that waiting. Like all glib async operations this honors the current get_thread_default.

In any case, to complete the shutdown, get_main_context must be iterated. If the current get_thread_default is the same as get_main_context, then integrate_maincontext is ignored. In that case, the caller is required to iterate the context for shutdown to complete. Otherwise, if get_thread_default differs from get_main_context and integrate_maincontext is false, the caller must make sure that both contexts are iterated until completion. Otherwise, if integrate_maincontext is true, then get_main_context will be integrated in get_thread_default. This means, the caller gives get_main_context up until the waiting completes, the function will acquire the context and hook it into get_thread_default. It is a bug to request integrate_maincontext while having get_main_context acquired or iterated otherwise because a context can only be acquired once at a time.

Shutdown can only complete after all references to this were released.

It is possible to call this function multiple times for the same client. But note that with integrate_maincontext the client's context is acquired, which can only be done once at a time.

It is permissible to start waiting before the objects is fully initialized.

The function really allows two separate things. To get a notification (callback) when shutdown is complete, and to integrate the client's context in another context. The latter case is useful if the client has a separate context and you hand it over to another GMainContext to wrap up.

The main use is to have a NMClient and a separate GMainContext on a worker thread. When being done, you can hand over the cleanup of the context to @default, assuming that the main thread iterates the default context. In that case, you don't need to care about passing a callback to know when shutdown completed.

Parameters:

this

the Client to shutdown.

integrate_maincontext

whether to hook the client's maincontext in the current thread default. Otherwise, you must ensure that the client's maincontext gets iterated so that it can complete. By integrating the maincontext in the current thread default, you may instead only iterate the latter.

cancellable

the Cancellable to abort the shutdown.

callback

a TaskReadyCallback to call when the request is satisfied or null if you don't care about the result of the method invocation.

user_data

the data to pass to callback