GLib.MainContext.prototype.wakeup

function wakeup(): void {
    // Gjs wrapper for g_main_context_wakeup()
}
  

If context is currently blocking in GLib.MainContext.prototype.iteration waiting for a source to become ready, cause it to stop blocking and return. Otherwise, cause the next invocation of GLib.MainContext.prototype.iteration to return without blocking.

This API is useful for low-level control over GLib.MainContext; for example, integrating it with main loop implementations such as GLib.MainLoop.

Another related use for this function is when implementing a main loop with a termination condition, computed from multiple threads:

|[<!-- language="C" --> #define NUM_TASKS 10 static volatile gint tasks_remaining = NUM_TASKS; ... while (g_atomic_int_get (&tasks_remaining) != 0) g_main_context_iteration (NULL, TRUE); ]| Then in a thread: |[<!-- language="C" --> perform_work();

if (g_atomic_int_dec_and_test (&tasks_remaining)) g_main_context_wakeup (NULL); ]|