Skip to content

yangyubo/Dispatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dispatch++

Dispatch++ provides header-only C++ APIs for Grand Central Dispatch (GCD or libdispatch).

Project Status

Dispatch++ is tested under:

  1. macOS 12.3, Apple Silicon
  2. GNU Linux 4.9, ARM Cortex A7 and A9, with Busybox.

It should also work on every platform that libdispatch supports.

Install

Clone the repository as a git submodule, or copy include/Dispatch++ folder to your project.

  1. Add Dispatch++ include directory in header search path.
  2. libdispatch is required.
  3. LLVM 12.0 or higher is required, enable C++20 features.

Features

  • The API align with Swift APIs.
  • Headers only.
  • Tested.

Usage

#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");
  });
}

TODO

  • Support DISPATCH_SOURCE_TYPE_PROC.
  • Support DISPATCH_SOURCE_TYPE_VM.
  • Support DISPATCH_SOURCE_TYPE_VNODE.
  • Make DispatchTime compatible with std::chrono::time_point.

Documentation

The official Dispatch documentation for Swift can be applied to Dispatch++.