core: add wp_core_timeout_add API

This commit is contained in:
Julian Bouzas 2020-02-12 13:20:17 -05:00
parent eaea2156cb
commit 5abdc2fb9e
2 changed files with 36 additions and 0 deletions

View file

@ -485,6 +485,38 @@ wp_core_idle_add (WpCore * self, GSourceFunc function, gpointer data,
return g_source_get_id (source);
}
/**
* wp_core_timeout_add:
* @self: the core
* @timeout_ms: the timeout in milliseconds
* @function: (scope notified): the function to call
* @data: (closure): data to pass to @function
* @destroy: (nullable): a function to destroy @data
*
* Adds a timeout callback to be called at regular intervals in the same
* #GMainContext as the one used by this core. The function is called repeatedly
* until it returns FALSE, at which point the timeout is automatically destroyed
* and the function will not be called again. The first call to the function
* will be at the end of the first interval. This is essentially the same as
* g_timeout_add_full(), but it adds the created #GSource on the #GMainContext
* used by this core instead of the default context.
*
* Returns: the ID (greater than 0) of the event source
*/
guint
wp_core_timeout_add (WpCore * self, guint64 timeout_ms,
GSourceFunc function, gpointer data, GDestroyNotify destroy)
{
g_autoptr (GSource) source = NULL;
g_return_val_if_fail (WP_IS_CORE (self), 0);
source = g_timeout_source_new (timeout_ms);
g_source_set_callback (source, function, data, destroy);
g_source_attach (source, self->context);
return g_source_get_id (source);
}
/**
* wp_core_sync:
* @self: the core

View file

@ -53,6 +53,10 @@ WP_API
guint wp_core_idle_add (WpCore * self, GSourceFunc function, gpointer data,
GDestroyNotify destroy);
WP_API
guint wp_core_timeout_add (WpCore * self, guint64 timeout_ms,
GSourceFunc function, gpointer data, GDestroyNotify destroy);
WP_API
gboolean wp_core_sync (WpCore * self, GCancellable * cancellable,
GAsyncReadyCallback callback, gpointer user_data);