Design idea: Async types
Problem
- The current API of some types is getting confusing for application developers who are not interested in asynchronous features
- It's not possible to implement the way being asynchronous is implemented
- It's not possible to join an asynchronous event (except by hacking a spinlock that unlocks in the callback or something silly like that)
Solution
- Moving all _async methods to an interface (a strategy context) and make it possible to implement the strategy
- The async-join design idea
- TnyFolder at this moment has a get_folder_async method. That would be moved to a context interface like TnyAsyncFolder
- Introduce a strategy like for example TnyGThreadAsyncFolderStrategy which would implement the TnyAsyncFolderStrategy interface which would provide the implementation for this method.
- TnyCamelFolder would implement both TnyFolder and TnyAsyncFolder and therefore have a async-strategy property.
For example
Together with the async-join design idea this would look like this:
static void
callback (TnyFolder *folder, gboolean cancelled, GError **err, gpointer user_data)
{
printf ("ABC\n");
}
static void
status_callback (TnyFolder *folder, const gchar *what, gint status, gint oftotal, gpointer user_data)
{
}
static void
my_routine (TnyAsyncFolder *folder, gpointer user_data)
{
TnyAsyncFolderStrategy *strategy = tny_gthread_async_folder_strategy_new ();
TnyAsyncJoinable *joinable = NULL;
/* This can of course happen more early in the game too */
tny_async_folder_set_async_strategy (folder, strategy);
tny_async_folder_refresh_async (folder, callback, status_callback, user_data, &joinable);
/* To join is optional of course */
tny_async_joinable_join (joinable);
printf ("DEF\n");
g_object_unref (G_OBJECT (joinable));
}
