Infinity.AsyncOperation

Fields

None

Methods

class

new (io, run_func, done_func, *user_data)

free ()

start ()

Details

class Infinity.AsyncOperation

Infinity.AsyncOperation is an opaque data type and should only be accessed via the public API functions.

classmethod new(io, run_func, done_func, *user_data)
Parameters:
Returns:

A new Infinity.AsyncOperation. Free with Infinity.AsyncOperation.free() to cancel the operation.

Return type:

Infinity.AsyncOperation

This function creates a new Infinity.AsyncOperation. The function given by run_func will be run asynchronously in a worker thread. Once the function finishes, its result is passed back to the main thread defined by io, and done_func is called with the computed result in the main thread.

To actually start the asynchronous operation, call Infinity.AsyncOperation.start(). This allows to save the returned value into a structure before starting the operation, avoiding a potential race condition if the asynchronous function finishes quickly.

The asynchronous operation can be canceled by calling Infinity.AsyncOperation.free() on the returned Infinity.AsyncOperation object. If the operation is not cancelled and after done_func has been called, the operation is freed automatically and must not be freed by the caller. The caller must also keep a reference to io while the operation is running. Before dropping your reference to io, make sure to free the asynchronous operation. When the last reference to io is dropped, the operation is freed automatically, since it cannot pass back its result to the main thread anymore.

free()

Frees the given asynchronous operation and cancels it if it is currently running. This should only be called to cancel a running operation, or to free an operation that has not been started. In all other cases, the operation is freed automatically.

start()
Raises:

GLib.Error

Returns:

True on success or False if the operation could not be started.

Return type:

bool

Starts the operation given in self. The operation must have been created before with Infinity.AsyncOperation.new(). If the operation cannot be started, error is set and False is returned. In that case, the operation must not be used anymore since it will be automatically freed.