GLib.idle_add
Description: Reference for GLib.idle_add

### Function

# GLibidle_add

since: 2.0

#### Declaration

    guint
    g_idle_add (
      GSourceFunc function,
      gpointer data
    )

#### Description

Adds a function to be called whenever there are no higher priority events pending to the default main loop. The function is given the default idle priority, `G_PRIORITY_DEFAULT_IDLE`. If the function returns `FALSE` it is automatically removed from the list of event sources and will not be called again.

See [memory management of sources][mainloop-memory-management] for details on how to handle the return value and memory management of `data`.

This internally creates a main loop source using `g_idle_source_new()` and attaches it to the global `GMainContext` using g_source_attach(), so the callback will be invoked in whichever thread is running that main context. You can do these steps manually if you need greater control or to use a custom main context.

Available since: 2.0

This function is not directly available to language bindings.

The implementation of this method is provided by `g_idle_add_full()` in language bindings

#### Parameters

`function`

  Type: `GSourceFunc`

  Function to call.

`data`

  Type: `gpointer`

  Data to pass to `function`.

  The argument can be `NULL`.
  The data is owned by the caller of the function.

#### Return value

Type: `guint`

The ID (greater than 0) of the event source.