Gets the cancellable for the async pair.
If the DexAsyncPair is discarded by it's callers, then it will automatically
be cancelled using g_cancellable_cancel().
a #GCancellable
a #DexAsyncPair
Resolves @async_pair with @instance.
a #DexAsyncPair
a #GType of %G_TYPE_BOXED
the boxed value to store
Rejects @async_pair with @error.
This function is meant to be used when manually wrapping
various #GAsyncReadyCallback based API.
The ownership of @error is taken when calling this function.
a #DexAsyncPair
a #GError
Resolves @async_pair with a value of @instance.
This function is meant to be used when manually wrapping
various #GAsyncReadyCallback based API.
The ownership of @instance is taken when calling this function.
a #DexAsyncPair
a #GObject
Resolves @async_pair with @value.
a #DexAsyncPair
a string or %NULL
Resolves @async_pair with @variant.
a #DexAsyncPair
the variant to resolve with
Sets whether or not the future should cancel the async operation when
the future is discarded. This happens when no more futures are awaiting
the completion of this future.
a #DexAsyncPair
if the operation should cancel when the future is discarded
`DexAsyncResult` is used to integrate a `DexFuture` with `GAsyncResult`.
Use this class when you need to expose the traditional async/finish
behavior of `GAsyncResult`.
Tracks the result of @future and uses the value to complete @async_result,
eventually calling the registered #GAsyncReadyCallback.
a #GAsyncResult
a #DexFuture
Gets the future for the #DexAsyncResult, or %NULL if a future
is not available.
a #DexFuture or %NULL
a #DexAsyncResult
#DexBlock represents a callback closure that can be scheduled to run
within a specific #GMainContext.
You create these by chaining futures together using dex_future_then(),
dex_future_catch(), dex_future_finally() and similar.
Gets the kind of block.
The kind of block relates to what situations the block would be
executed such as for handling a future resolution, rejection, or
both.
a #DexBlockKind
a #DexBlock
Gets the scheduler to use when executing a block.
a #DexScheduler
a #DexBlock
`DexCancellable` is a simple cancellation primitive which allows
for you to create `DexFuture` that will reject upon cancellation.
Use this combined with other futures using dex_future_all_race()
to create a future that resolves when all other futures complete
or `dex_cancellable_cancel()` is called to reject.
Creates a new #DexChannel.
If capacity is non-zero, it can be used to limit the size of the channel
so that functions can asynchronously stall until items have been removed
from the channel. This is useful in buffering situations so that the
producer does not outpace the consumer.
a new #DexChannel
the channel queue depth or 0 for unlimited
Receives the next item from the channel.
The resulting future will resolve or reject when an item is available
to the channel or when send side has closed (in that order).
a #DexFuture
a #DexChannel
Will attempt to receive all items in the channel as a #DexResultSet.
If the receive side of the channel is closed, then the future will
reject with an error.
If there are items in the queue, then they will be returned as part
of a #DexResultSet containing each of the futures.
Otherwise, a #DexFutureSet will be returned which will resolve or
reject when the next item is available in the channel (or the send
or receive sides are closed).
a #DexFuture
a #DexChannel
Queues @future into the channel.
The other end of the channel can receive the future (or a future that will
eventually resolve to @future) using dex_channel_receive().
This function returns a #DexFuture that will resolve when the channels
capacity is low enough to queue more items.
If the send side of the channel is closed, the returned #DexFuture will be
rejected with %DEX_ERROR_CHANNEL_CLOSED.
a #DexFuture
a #DexChannel
a #DexFuture
#DexDelayed is a future which will resolve or reject the value of another
#DexFuture when dex_delayed_release() is called.
This allows you to gate the resolution of a future which has already
resolved or rejected until a later moment.
Retrieves the delayed future provided to dex_delayed_new().
This function can only return a #DexFuture before dex_delayed_release()
is called. After that, the delayed future is released and this function
will return %NULL.
a #DexFuture or %NULL
a #DexDelayed
#DexFiber is a fiber (or coroutine) which itself is a #DexFuture.
When the fiber completes execution it will either resolve or reject the
with the result or error.
You may treat a #DexFiber like any other #DexFuture which makes it simple
to integrate fibers into other processing chains.
#DexFiber are provided their own stack seperate from a threads main stack,
They are automatically scheduled as necessary.
Use dex_await() and similar functions to await the result of another future
within the fiber and the fiber will be suspended allowing another fiber to
run and/or the rest of the applications main loop.
Once a fiber is created, it is pinned to that scheduler. Use
dex_scheduler_spawn() to create a fiber on a specific scheduler.
This function prototype is used for spawning fibers. A fiber
is a lightweight, cooperative-multitasking feature where the
fiber is given it's own stack. The fiber runs until it reaches
a point of suspension (using `dex_await` or similar) or exits
the fiber.
When suspended, the fiber is placed onto a queue until it is
runnable again. Once runnable, the fiber is scheduled to run
from within whatever scheduler it was created with.
See `dex_scheduler_spawn()`
a #DexFuture or %NULL
#DexFuture is the base class representing a future which may resolve with
a value or reject with error at some point in the future.
It is the basis for libdex's concurrency and parallelism model.
Use futures to represent work in progress and allow consumers to build
robust processing chains up front which will complete or fail as futures
resolve or reject.
When running on a #DexFiber, you may use dex_await() and similar functions
to suspend the current thread and return upon completion of the dependent
future.
Creates a new #DexFuture that will resolve or reject when all futures
either resolve or reject.
This method will return a #DexFutureSet which provides API to get
the exact values of the dependent futures. The value of the future
if resolved will be a %G_TYPE_BOOLEAN of %TRUE.
a #DexFutureSet
a #DexFuture
a %NULL terminated list of futures
Creates a new #DexFuture that will resolve when all futures resolve
or reject as soon as the first future rejects.
This method will return a #DexFutureSet which provides API to get
the exact values of the dependent futures. The value of the future
will be propagated from the resolved or rejected future.
Since the futures race to complete, some futures retrieved with the
dex_future_set_get_future() API will still be %DEX_FUTURE_STATUS_PENDING.
a #DexFutureSet
a #DexFuture
a %NULL terminated list of futures
Creates a new #DexFuture that resolves when all futures resolve.
If any future rejects, the resulting #DexFuture also rejects immediately.
a #DexFuture
an array of futures
the number of futures
Creates a new #DexFuture that resolves when all futures resolve.
The resulting #DexFuture will not resolve or reject until all futures
have either resolved or rejected.
a #DexFuture
an array of futures
the number of futures
Creates a new #DexFuture that will resolve when any dependent future
resolves, providing the same result as the resolved future.
If no futures resolve, then the future will reject.
a #DexFutureSet
a #DexFuture
a %NULL terminated list of futures
Creates a new #DexFuture that resolves when the first future resolves.
If all futures reject, then the #DexFuture returned will also reject.
a #DexFuture
an array of futures
the number of futures
Calls @callback when @future rejects.
If @future resolves, then @callback will not be called.
a #DexFuture
a #DexFuture
a callback to execute
closure data for @callback
destroy notify for @callback_data
Asynchronously calls @callback when @future rejects.
This is similar to dex_future_catch() except that it will call
@callback multiple times as each returned #DexFuture rejects,
allowing for infinite loops.
a #DexFuture
a #DexFuture
a callback to execute
closure data for @callback
destroy notify for @callback_data
Calls @callback when @future resolves or rejects.
a #DexFuture
a #DexFuture
a callback to execute
closure data for @callback
destroy notify for @callback_data
Asynchronously calls @callback when @future rejects or resolves.
This is similar to dex_future_finally() except that it will call
@callback multiple times as each returned #DexFuture rejects or resolves,
allowing for infinite loops.
a #DexFuture
a #DexFuture
a callback to execute
closure data for @callback
destroy notify for @callback_data
Creates a new #DexFuture that resolves or rejects as soon as the
first dependent future resolves or rejects, sharing the same result.
a #DexFutureSet
a #DexFuture
a %NULL terminated list of futures
Creates a new #DexFuture that resolves or rejects as soon as the
first dependent future resolves or rejects, sharing the same result.
a #DexFuture
an array of futures
the number of futures
Creates a new #DexFuture and resolves it with @v_bool.
a resolved #DexFuture
the resolved value for the future
Creates a new #DexFuture and resolves it with @v_double.
a resolved #DexFuture
the resolved value for the future
Creates a new rejected future using @errno_ as the value
of errno for the GError.
The resulting error domain will be %G_IO_ERROR.
a rejected #DexFuture.
the `errno` to use for rejection
Creates a read-only #DexFuture that has rejected.
a #DexFuture
a #GError
Creates a new #DexFuture and resolves it with @v_float.
a resolved #DexFuture
the resolved value for the future
Creates a new #DexFuture and resolves it with @v_int.
a resolved #DexFuture
the resolved value for the future
Creates a new #DexFuture and resolves it with @v_int64.
a resolved #DexFuture
the resolved value for the future
Creates a new #DexFuture that is resolved with @value.
a resolved #DexFuture
the value
Creates a new #DexFuture that is resolved with @pointer as a %G_TYPE_POINTER.
a resolved #DexFuture
the resolved future value as a pointer
Creates a new #DexFuture and resolves it with @string.
a resolved #DexFuture
the resolved value for the future
Creates a new #DexFuture and resolves it with @v_uint.
a resolved #DexFuture
the resolved value for the future
Creates a new #DexFuture and resolves it with @v_uint64.
a resolved #DexFuture
the resolved value for the future
Creates a read-only #DexFuture that has resolved.
a #DexFuture
the resolved #GValue
Creates an infinite future that will never resolve or reject. This can
be useful when you want to mock a situation of "run forever" unless
another future rejects or resolves.
a #DexFuture that will never complete or reject
Creates a new #DexFuture that is rejeced.
a new #DexFuture
the error domain
the error code
a printf-style format string
Creates a new #DexFuture that is resolved with @value.
a resolved #DexFuture
the GBoxed-based type
the value for the boxed type
Creates a new #DexFuture that is resolved with @value.
a resolved #DexFuture
the value
Creates a new #DexFuture and resolves it with @string.
a resolved #DexFuture
the resolved value for the future
Creates a new #DexFuture that is resolved with @v_variant.
a resolved #DexFuture
the variant to take ownership of
Calls @callback when @future resolves.
If @future rejects, then @callback will not be called.
a #DexFuture
a #DexFuture
a callback to execute
closure data for @callback
destroy notify for @callback_data
Asynchronously calls @callback when @future resolves.
This is similar to dex_future_then() except that it will call
@callback multiple times as each returned #DexFuture resolves or
rejects, allowing for infinite loops.
a #DexFuture
a #DexFuture
a callback to execute
closure data for @callback
destroy notify for @callback_data
Suspends the current #DexFiber and resumes when @future has completed.
If @future is completed when this function is called, the fiber will handle
the result immediately.
This function may only be called within a #DexFiber. To do otherwise will
return %FALSE and @error set to %DEX_ERROR_NO_FIBER.
It is an error to call this function in a way that would cause
intermediate code to become invalid when resuming the stack. For example,
if a foreach-style function taking a callback was to suspend from the
callback, undefined behavior may occur such as thread-local-storage
having changed.
%TRUE if the future resolved, otherwise %FALSE
and @error is set.
a #DexFuture
Awaits on @future and returns the gboolean result.
If the result is not a #gboolean, @error is set.
the #gboolean, or %FALSE and @error is set
a #DexFuture
Awaits on @future and returns the %G_TYPE_BOXED based result.
the boxed result, or %NULL and @error is set.
a #DexFuture
Awaits on @future and returns the result as an double.
The resolved value must be of type %G_TYPE_INT or @error is set.
an double, or 0 in case of failure and @error is set.
a #DexFuture
Awaits on @future and returns the enum result.
If the result is not a %G_TYPE_ENUM, @error is set.
the enum or 0 and @error is set.
a #DexFuture
Awaits on @future and returns the flags result.
If the result is not a %G_TYPE_FLAGS, @error is set.
the flags or 0 and @error is set.
a #DexFuture
Awaits on @future and returns the result as an float.
The resolved value must be of type %G_TYPE_INT or @error is set.
an float, or 0 in case of failure and @error is set.
a #DexFuture
Awaits on @future and returns the result as an int.
The resolved value must be of type %G_TYPE_INT or @error is set.
an int, or 0 in case of failure and @error is set.
a #DexFuture
Awaits on @future and returns the result as an int64.
The resolved value must be of type %G_TYPE_INT64 or @error is set.
an int64, or 0 in case of failure and @error is set.
a #DexFuture
Awaits on @future and returns the #GObject-based result.
the object, or %NULL and @error is set.
a #DexFuture
Calls dex_await() and returns the value of g_value_get_pointer(),
otherwise @error is set if the future rejected.
a pointer or %NULL
a #DexFuture
Awaits on @future and returns the string result.
If the result is not a %G_TYPE_STRING, @error is set.
the string or %NULL and @error is set
a #DexFuture
Awaits on @future and returns the result as an uint.
The resolved value must be of type %G_TYPE_INT or @error is set.
an uint, or 0 in case of failure and @error is set.
a #DexFuture
Awaits on @future and returns the result as an uint64.
The resolved value must be of type %G_TYPE_INT64 or @error is set.
an uint64, or 0 in case of failure and @error is set.
a #DexFuture
Awaits on @future and returns the %G_TYPE_VARIANT based result.
the variant result, or %NULL and @error is set.
a #DexFuture
Disowns a future, allowing it to run to completion even though there may
be no observer interested in the futures completion or rejection.
a #DexFuture
This is a convenience function equivalent to calling
dex_future_get_status() and checking for %DEX_FUTURE_STATUS_PENDING.
%TRUE if the future is still pending; otherwise %FALSE
a #DexFuture
This is a convenience function equivalent to calling
dex_future_get_status() and checking for %DEX_FUTURE_STATUS_REJECTED.
%TRUE if the future was rejected with an error; otherwise %FALSE
a #DexFuture
This is a convenience function equivalent to calling
dex_future_get_status() and checking for %DEX_FUTURE_STATUS_RESOLVED.
%TRUE if the future has successfully resolved with a value;
otherwise %FALSE
a #DexFuture
Sets the name of the future with a static/internal string.
@name will not be copied, so it must be static/internal which can be done
either by using string literals or by using g_string_intern().
a #DexFuture
the name of the future
A #DexFutureCallback can be executed from a #DexBlock as response to
another #DexFuture resolving or rejecting.
The callback will be executed within the scheduler environment the
block is created within when using dex_future_then(), dex_future_catch(),
dex_future_finally(), dex_future_all(), and similar functions.
This is the expected way to handle completion of a future when not using
#DexFiber via dex_scheduler_spawn().
a #DexFuture or %NULL
a resolved or rejected #DexFuture
closure data associated with the callback
#DexFutureSet represents a set of #DexFuture.
You may retrieve each underlying #DexFuture using
dex_future_set_get_future_at().
The #DexFutureStatus of of the #DexFutureSet depends on how the set
was created using dex_future_all(), dex_future_any(), and similar mmethods.
Gets a #DexFuture that was used to produce the result of @future_set.
Use dex_future_set_get_size() to determine the number of #DexFuture that
are contained within the #DexFutureSet.
a #DexFuture
a #DexFutureSet
Gets the number of futures associated with the #DexFutureSet. You may
use dex_future_set_get_future_at() to obtain the individual #DexFuture.
the number of #DexFuture in @future_set.
a #DexFutureSet
Gets the result from a #DexFuture that is part of the
#DexFutureSet.
a #GValue if successful; otherwise %NULL
and @error is set.
a #DexFutureSet
the #DexFuture position within the set
#DexMainScheduler is the scheduler used on the default thread of an
application. It is meant to integrate with your main loop.
This scheduler does the bulk of the work in an application.
Use #DexThreadPoolScheduler when you want to offload work to a thread
and still use future-based programming.
`DexObject` is the basic building block of types defined within
libdex. Futures, Schedulers, and Channels all inherit from DexObject
which provides features like thread-safe weak pointers and memory
management operations.
Objects that are integrating with GIO instead inherit from their
natural type in GIO.
Acquires a reference on the given object, and increases its reference count by one.
the object with its reference count increased
the object to reference
Releases a reference on the given object, and decreases its reference count by one.
If it was the last reference, the resources associated to the instance are freed.
the object to unreference
#DexPromise is a convenient #DexFuture for prpoagating a result or
rejection in appliction and library code.
Use this when there is not a more specialized #DexFuture for your needs to
propagate a result or rejection to the caller in an asynchronous fashion.
Creates a new #DexPromise that can propagate cancellation if the
promise is discarded.
This can be used to plumb cancellation between promises and
#GAsyncReadyCallback based APIs.
a #DexPromise
Gets a #GCancellable that will cancel when the promise has
been discarded (and therefore result no longer necessary).
This is useful when manually implementing wrappers around various
#GAsyncReadyCallback based API.
If @promise was created with dex_promise_new(), then %NULL is returned.
a #GCancellable or %NULL
a #DexPromise
Marks the promise as rejected, indicating a failure.
a #DexPromise
a #GError
Sets the result for a #DexPromise.
a #DexPromise
a #GValue containing the resolved value
a #DexPromise
a #GObject
a #DexPromise
a string to use to resolve the promise
If @variant is floating, it's reference is consumed.
a #DexPromise
a #GVariant
#DexScheduler is the base class used by schedulers.
Schedulers are responsible for ensuring asynchronous IO requests and
completions are processed. They also schedule closures to be run as part
of future result propagation. Additionally, they manage #DexFiber execution
and suspension.
Specialized schedulers such as #DexThreadPoolScheduler will do this for a
number of threads and dispatch new work between them.
Gets the default scheduler for the process.
The default scheduler executes tasks within the default #GMainContext.
Typically that is the main thread of the application.
a #DexScheduler
Gets the default scheduler for the thread.
a #DexScheduler or %NULL
Gets the thread default scheduler with the reference count incremented.
a #DexScheduler or %NULL
Gets the default main context for a scheduler.
This may be a different value depending on the calling thread.
For example, calling this on the #DexThreadPoolScheduer from outside
a worker thread may result in getting a shared #GMainContext for the
process.
However, calling from a worker thread may give you a #GMainContext
specifically for that thread.
a #GMainContext
a #DexScheduler
Queues @func to run on @scheduler.
a #DexScheduler
the function callback
the closure data for @func
Request @scheduler to spawn a #DexFiber.
The fiber will have it's own stack and cooperatively schedules among other
fibers sharing the schaeduler.
If @stack_size is 0, it will set to a sensible default. Otherwise, it is
rounded up to the nearest page size.
a #DexFuture that will resolve or reject when
@func completes (or it's resulting #DexFuture completes).
a #DexScheduler
stack size in bytes or 0
a #DexFiberFunc
closure data for @func
closure notify for @func_data
`DexStaticFuture` represents a future that is resolved from the initial
state.
Use this when you need to create a future for API reasons but already have
the value or rejection at that point.
#DexStaticFuture is used internally by functions like
dex_future_new_for_boolean() and similar.
#DexThreadPoolScheduler is a #DexScheduler that will dispatch work items
and fibers to sub-schedulers on a specific operating system thread.
#DexFiber will never migrate from the thread they are created on to reduce
chances of safety issues involved in tracking state between CPU.
New work items are placed into a global work queue and then dispatched
efficiently to a single thread pool worker using a specialized async
semaphore. On modern Linux using io_uring, this wakes up a single worker
thread and therefore is not subject to "thundering herd" common with
global work queues.
When a worker creates a new work item, it is placed into a work stealing
queue owned by the thread. Other worker threads may steal work items when
they have exhausted their own work queue.
Creates a new #DexScheduler that executes work items on a thread pool.
a #DexThreadPoolScheduler
Gets the default thread pool scheduler for the instance.
This function is useful to allow programs and libraries to share
an off-main-thread scheduler without having to coordinate on where
the scheduler instance is created or owned.
a #DexScheduler
#DexTimeout is a #DexFuture that will resolve after the configured
period of time.
#DexUnixSignal is a #DexFuture that will resolve when a specific unix
signal has been received.
Use this when you want to handle a signal from your main loop rather than
from a resticted operating signal handler.
On Linux, this uses a signalfd.
Creates a new #DexUnixSignal that completes when @signum is delivered
to the process.
@signum must be one of SIGHUP, SIGINT, SIGTERM, SIGUSR1, SIGUSR2, or
SIGWINCH.
This API is only supported on UNIX-like systems.
a new #DexFuture
a unix signal number
An asynchronous `pread()` wrapper.
a future that will resolve when the
read completes or rejects with error.
An asynchronous `pwrite()` wrapper.
a future that will resolve when the
write completes or rejects with error.
Wrapper for g_bus_get().
a #DexFuture that resolves to a #GDBusConnection
or rejects with error.
Wrapper for g_dbus_connection_call().
a #DexFuture that resolves to a #GVariant
or rejects with error.
Wrapper for g_dbus_connection_call_with_unix_fd_list().
a #DexFutureSet that resolves to a #GVariant.
The #DexFuture containing the resulting #GUnixFDList can be retrieved
with dex_future_set_get_future_at() with an index of 1.
a #GUnixFDList
Wrapper for g_dbus_connection_send_message_with_reply().
a #DexFuture that will resolve to a #GDBusMessage
or reject with failure.
a #GDBusConnection
a #GDBusMessage
flags for @message
timeout in milliseconds, or -1 for default, or %G_MAXINT
for no timeout.
a location for the message serial number
Asynchronously copies a file and returns a #DexFuture which
can be observed for the result.
a #DexFuture
a #GFile
a #GFile
the #GFileCopyFlags
IO priority such as %G_PRIORITY_DEFAULT
a #DexFuture
a #DexFuture
a #DexFuture
Asynchronously creates a directory and returns #DexFuture which
can be observed for the result.
a #DexFuture
a #GFile
IO priority such as %G_PRIORITY_DEFAULT
Queries to see if @file exists asynchronously.
a #DexFuture that will resolve with %TRUE
if the file exists, otherwise reject with error.
a #GFile
a #DexFuture
Asynchronously opens a file for reading.
a #DexFuture
a #GFile
IO priority such as %G_PRIORITY_DEFAULT
a #DexFuture
a #DexFuture
a #DexFuture
a #DexFuture
a #DexFuture
the number of bytes to skip
%G_PRIORITY_DEFAULT or similar priority value
a #DexFuture
a #DexFuture
a #DexFuture
a #DexFuture
a #DexFuture
a #DexFuture
a #DexFuture
a #DexFuture
Creates a future that awaits for @subprocess to complete using
g_subprocess_wait_check_async().
a #DexFuture that will resolve when @subprocess
exits cleanly or reject upon signal or non-successful exit.
a #GSubprocess
Retrieves the `DexObject` stored inside the given `value`.
a `DexObject`
a `GValue` initialized with type `DEX_TYPE_OBJECT`
Stores the given `DexObject` inside `value`.
The [struct@GObject.Value] will acquire a reference to the `object`.
a [struct@GObject.Value] initialized with type `DEX_TYPE_OBJECT`
a `DexObject` or %NULL
Stores the given `DexObject` inside `value`.
This function transfers the ownership of the `object` to the `GValue`.
a [struct@GObject.Value] initialized with type `DEX_TYPE_OBJECT`
a `DexObject`