connect
Description:
Convenience function to connect to the cancelled signal.
Also handles the race condition that may happen if the cancellable is cancelled right before connecting.
callback is called exactly once each time this is cancelled, either directly at the time of the
connect if this is already cancelled, or when this is cancelled in some
thread. In case the cancellable is reset via [method@Gio.Cancellable.reset] then the callback can be called again if the
this is cancelled and if it had not been previously cancelled at the time [method@Gio.Cancellable.connect] was
called (e.g. if the connection actually took place, returning a non-zero value).
data_destroy_func will be called when the handler is disconnected, or immediately if the cancellable is already cancelled.
See cancelled for details on how to use this.
Since GLib 2.40, the lock protecting this 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. [
method@Gio.Cancellable.cancel]. Note that since 2.82 GLib still holds a lock during the callback but it’s designed in a way that most of the [
class@Gio.Cancellable] methods can be called, including [method@Gio.Cancellable.cancel] or [method@GObject.Object.unref].
There are still some methods that will deadlock (by design) when called from the [signal@Gio.Cancellable:GCancellable:cancelled]
callbacks: - [method@Gio.Cancellable.connect] - [method@Gio.Cancellable.disconnect] - [method@Gio.Cancellable.reset] - [
method@Gio.Cancellable.make_pollfd] - [method@Gio.Cancellable.release_fd]
Parameters:
| this |
A Cancellable. |
| callback |
The ObjectConstructorFunc to connect. |
| data |
Data to pass to |
| data_destroy_func |
Free function for |
Returns:
|
The id of the signal handler or 0 if this has already been cancelled. |