codegen: Use GTask instead of GSimpleAsyncResult if 2.36 target is selected
GTask brings some differences compared to GSimpleAsyncResult. Most namely,
g_task_return*() operations perform at once the async result data asignment
and the caller's main context activation. This is something that has to be
done exactly once, so the code flow has slight changes to ensure that.
Also, the async operation data used to be attached early through
g_simple_async_result_set_op_res_gpointer, only to be maybe replaced by
the real return data. If GTask is being used, we set this data through
g_task_set_task_data().
There's code out there relying on immediate return here when state is
!=0. As GTask always defers the finalization to an idle in its main
context, ensure the source is dispatched and the task completed before
returning.