Cancellable

GCancellable is a thread-safe operation cancellation stack used throughout GIO to allow for cancellation of synchronous and asynchronous operations.

Constructors

this
this(GCancellable* gCancellable, bool ownedRef = false)

Sets our main struct and passes it to the parent class.

this
this()

Creates a new GCancellable object.

Members

Functions

addOnCancelled
gulong addOnCancelled(void delegate(Cancellable) dlg, ConnectFlags connectFlags = cast(ConnectFlags)0)

Emitted when the operation has been cancelled.

cancel
void cancel()

Will set cancellable to cancelled, and will emit the cancelled signal. (However, see the warning about race conditions in the documentation for that signal if you are planning to connect to it.)

connect
gulong connect(GCallback callback, void* data, GDestroyNotify dataDestroyFunc)

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

disconnect
void disconnect(gulong handlerId)

Disconnects a handler from a cancellable instance similar to g_signal_handler_disconnect(). Additionally, in the event that a signal handler is currently running, this call will block until the handler has finished. Calling this function from a cancelled signal handler will therefore result in a deadlock.

getCancellableStruct
GCancellable* getCancellableStruct(bool transferOwnership = false)

Get the main Gtk struct

getFd
int getFd()

Gets the file descriptor for a cancellable job. This can be used to implement cancellable operations on Unix systems. The returned fd will turn readable when cancellable is cancelled.

getStruct
void* getStruct()

the main Gtk struct as a void*

isCancelled
bool isCancelled()

Checks if a cancellable job has been cancelled.

makePollfd
bool makePollfd(GPollFD* pollfd)

Creates a GPollFD corresponding to cancellable; this can be passed to g_poll() and used to poll for cancellation. This is useful both for unix systems without a native poll and for portability to windows.

popCurrent
void popCurrent()

Pops cancellable off the cancellable stack (verifying that cancellable is on the top of the stack).

pushCurrent
void pushCurrent()

Pushes cancellable onto the cancellable stack. The current cancellable can then be received using g_cancellable_get_current().

releaseFd
void releaseFd()

Releases a resources previously allocated by g_cancellable_get_fd() or g_cancellable_make_pollfd().

reset
void reset()

Resets cancellable to its uncancelled state.

setErrorIfCancelled
bool setErrorIfCancelled()

If the cancellable is cancelled, sets the error to notify that the operation was cancelled.

sourceNew
Source sourceNew()

Creates a source that triggers if cancellable is cancelled and calls its callback of type GCancellableSourceFunc This is primarily useful for attaching to another (non-cancellable) source with g_source_add_child_source() to add cancellability to it.

Static functions

getCurrent
Cancellable getCurrent()

Gets the top cancellable from the stack.

getType
GType getType()

Variables

gCancellable
GCancellable* gCancellable;

the main Gtk struct