Method

GioCancellableconnect

Declaration

gulong
g_cancellable_connect (
  GCancellable* cancellable,
  GCallback callback,
  gpointer data,
  GDestroyNotify data_destroy_func
)

Description

Convenience function to connect to the GCancellable::cancelled signal. Also handles the race condition that may happen if the cancellable is cancelled right before connecting.

callback is called at most once, either directly at the time of the connect if cancellable is already cancelled, or when cancellable is cancelled in some thread.

data_destroy_func will be called when the handler is disconnected, or immediately if the cancellable is already cancelled.

See GCancellable::cancelled for details on how to use this.

Since GLib 2.40, the lock protecting cancellable is not held when callback is invoked. This lifts a restriction in place for earlier GLib versions which now makes it easier to write cleanup code that unconditionally invokes e.g. g_cancellable_cancel().

Available since:2.22

Parameters

callback GCallback
 

The GCallback to connect.

data gpointer
 

Data to pass to callback.

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

Free function for data or NULL.

 The argument can be NULL.

Return value

Returns: gulong
 

The id of the signal handler or 0 if cancellable has already been cancelled.