#include <glib.h>
#include <gio/gio.h>


void
test_two_async(GAsyncReadyCallback callback, gpointer user_data)
{
  GSimpleAsyncResult *res = g_simple_async_result_new (NULL,
						       callback,
						       user_data,
						       NULL); 
  g_simple_async_result_complete_in_idle(res);
  g_object_unref(res);
}


void
test_over(GObject *src_obj, GAsyncResult *res, gpointer user_data)
{
  g_debug("COMPLETE SUCCESS");
}

void
test_one_over(GObject *src_obj, GAsyncResult *res, gpointer user_data)
{
  g_debug("STEP 2");
  g_simple_async_result_complete_in_idle(user_data);
  g_object_unref(res);
}

void
test_one_step_one(GObject *src_obj, GAsyncResult *res, gpointer user_data)
{
  test_two_async(test_one_over, user_data);
  g_debug("STEP 1");
}

void
test_one_async (GAsyncReadyCallback callback, gpointer user_data)
{
  GSimpleAsyncResult *res = g_simple_async_result_new (NULL,
						       callback,
						       user_data,
						       NULL);
  test_two_async(test_one_step_one, res);
}

int main (int argc, char **argv)
{
  GMainContext *ctx;
  GMainLoop *loop;

  g_type_init();

  ctx = g_main_context_new();
  loop = g_main_loop_new(ctx, FALSE);

  g_main_context_push_thread_default(ctx);
  test_one_async(test_over, NULL);
  g_main_context_pop_thread_default(ctx);

  g_main_loop_run (loop);

  return 0;
}
