Dispatch++
provides header-only C++ APIs for Grand Central Dispatch (GCD or libdispatch).
Dispatch++
is tested under:
- macOS 12.3, Apple Silicon
- GNU Linux 4.9, ARM Cortex A7 and A9, with Busybox.
It should also work on every platform that libdispatch supports.
Clone the repository as a git submodule, or copy include/Dispatch++
folder to your project.
- Add
Dispatch++
include directory in header search path. - libdispatch is required.
- LLVM 12.0 or higher is required, enable C++20 features.
- The API align with Swift APIs.
- Headers only.
- Tested.
#include <Dispatch++/Dispatch.h>
int main() {
DispatchQueue queue = DispatchQueue{"dispatch.dispatch-after"};
// after 6 seconds
auto time_a = DispatchTime::now() + DispatchTimeInterval::seconds(6);
queue.asyncAfter(time_a, ^{
printf("Hello, World!\n");
});
}
- Support
DISPATCH_SOURCE_TYPE_PROC
. - Support
DISPATCH_SOURCE_TYPE_VM
. - Support
DISPATCH_SOURCE_TYPE_VNODE
. - Make
DispatchTime
compatible withstd::chrono::time_point
.
The official Dispatch documentation for Swift can be applied to Dispatch++
.