Skip to content

girepository: Add support for typelib async loading

Add an API to load typelibs in different threads, so that bindings can actually perform async imports of typelibs and not block on IO when doing library imports.

Threads are created only when this is actually needed, otherwise we just return what we have.

Multiple threads can request a specific module concurrently, but only first one will actually do the loading.

To allow cancellation of async requests, given that we can't depend on Gio directly, I've added a simple implementation for a "cancellable" struct that can be passed to the calling function and that allows the caller to cancel the operation atomically without having to monitor the requests in other ways (such as keeping a list of requests and allowing them to be cancelled via another function).

Right now the operation can't be cancelled given we can't really use GCancellable in this context, however an option is to make this function to return an ID and then we can avoid calling the callback if a g_irepository_require_async is called with given ID.

It increases lightly the complexity, and I'm not sure it's really needed (as callers can protect themselves in other way) but let me know if that should be added instead.

Edited by Marco Trevisan

Merge request reports