| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#include <libdex.h> |
| 22 |
|
| 23 |
static DexFuture * |
| 24 |
infinite_loop_cb (DexFuture *future, |
| 25 |
gpointer user_data) |
| 26 |
{ |
| 27 |
const GValue *value; |
| 28 |
GMainLoop *main_loop = user_data; |
| 29 |
GError *error = NULL; |
| 30 |
|
| 31 |
if ((value = dex_future_get_value (future, &error))) |
| 32 |
{ |
| 33 |
g_print ("\nCaught signal %u, exiting.\n", |
| 34 |
g_value_get_int (value)); |
| 35 |
g_main_loop_quit (main_loop); |
| 36 |
return NULL; |
| 37 |
} |
| 38 |
|
| 39 |
g_print ("Looping ...\n"); |
| 40 |
|
| 41 |
return dex_future_first (dex_timeout_new_seconds (1), |
| 42 |
#ifdef G_OS_UNIX |
| 43 |
dex_unix_signal_new (SIGINT), |
| 44 |
#endif |
| 45 |
NULL); |
| 46 |
} |
| 47 |
|
| 48 |
int |
| 49 |
main (int argc, |
| 50 |
char *argv[]) |
| 51 |
{ |
| 52 |
GMainLoop *main_loop; |
| 53 |
DexFuture *loop; |
| 54 |
|
| 55 |
dex_init (); |
| 56 |
|
| 57 |
main_loop = g_main_loop_new (NULL, FALSE); |
| 58 |
loop = dex_future_finally_loop (dex_future_first (dex_timeout_new_seconds (1), |
| 59 |
#ifdef G_OS_UNIX |
| 60 |
dex_unix_signal_new (SIGINT), |
| 61 |
#endif |
| 62 |
NULL), |
| 63 |
infinite_loop_cb, |
| 64 |
g_main_loop_ref (main_loop), |
| 65 |
(GDestroyNotify)g_main_loop_unref); |
| 66 |
|
| 67 |
g_main_loop_run (main_loop); |
| 68 |
|
| 69 |
dex_unref (loop); |
| 70 |
g_main_loop_unref (main_loop); |
| 71 |
|
| 72 |
return 0; |
| 73 |
} |