camel-async-closure

camel-async-closure — Run asynchronous functions synchronously

Types and Values

Includes

#include <camel/camel.h>

Description

CamelAsyncClosure provides a simple way to run an asynchronous function synchronously without blocking the current thread.

1) Create a CamelAsyncClosure with camel_async_closure_new().

2) Call the asynchronous function passing camel_async_closure_callback() as the GAsyncReadyCallback argument and the CamelAsyncClosure as the data argument.

3) Call camel_async_closure_wait() and collect the GAsyncResult.

4) Call the corresponding asynchronous "finish" function, passing the GAsyncResult returned by camel_async_closure_wait().

5) If needed, repeat steps 2-4 for additional asynchronous functions using the same CamelAsyncClosure.

6) Finally, free the CamelAsyncClosure with camel_async_closure_free().

Functions

camel_async_closure_new ()

CamelAsyncClosure *
camel_async_closure_new (void);

Creates a new CamelAsyncClosure for use with asynchronous functions.

Returns

a new CamelAsyncClosure

Since: 3.12


camel_async_closure_wait ()

GAsyncResult *
camel_async_closure_wait (CamelAsyncClosure *closure);

Call this function immediately after starting an asynchronous operation. The function waits for the asynchronous operation to complete and returns its GAsyncResult to be passed to the operation's "finish" function.

This function can be called repeatedly on the same CamelAsyncClosure to easily string together multiple asynchronous operations.

Parameters

closure

a CamelAsyncClosure

 

Returns

a GAsyncResult which is owned by the closure.

[transfer none]

Since: 3.12


camel_async_closure_free ()

void
camel_async_closure_free (CamelAsyncClosure *closure);

Frees the closure and the resources it holds.

Parameters

closure

a CamelAsyncClosure

 

Since: 3.12


camel_async_closure_callback ()

void
camel_async_closure_callback (GObject *source_object,
                              GAsyncResult *result,
                              gpointer closure);

Pass this function as the GAsyncReadyCallback argument of an asynchronous function, and the CamelAsyncClosure as the data argument.

This causes camel_async_closure_wait() to terminate and return result .

Parameters

source_object

a GObject or NULL

 

result

a GAsyncResult

 

closure

a CamelAsyncClosure

 

Since: 3.12

Types and Values

CamelAsyncClosure

typedef struct _CamelAsyncClosure CamelAsyncClosure;

Contains only private data that should be read and manipulated using the functions below.

Since: 3.12