A delay-queue implemented in C++ that defers execution of tasks by a period of time that is configurable by users.
- Allows users to specify a delay period for a given task
- Returns a
std::future
for the task specified so users can wait for the completion of task and retrieve the return value - Provides high throughput of processing via thread-pools designed underneath
This project is built via Bazel, which can be downloaded and installed at here.
You can use Homebrew:
brew tap bazelbuild/tap
brew install bazelbuild/tap/bazel
You can execute the scripts/install.sh
after specifying appropriate Bazel version
in the shell.
export BAZEL_VERSION=3.1.0
./scripts/install.sh
To build and test your branch, simply execute the following
bazel build ...
bazel test ...
To build in development mode with debug symbols, run the following:
bazel build -c dbg ...
bazel test -c dbg ...
You can go to Bazel's Official Documentations to learn more about how to use it.
You should specify a task by wrapping the function and parameters via the std::bind
call. For example, the following code snippet defines a delay queue and add a task to
execute function foo
with parameters 1 and 2:
#include "delay_queue.h"
int foo(int a, int b) {
return a + b;
}
DelayQueue delay_queue;
std::future<int> task_future = delay_queue.AddTask(
/* Delay period in milliseconds */ 1000,
std::bind(&foo, 1, 2));
int res = task_future.get();
where the first parameter taken by DelayQueue::AddTask is an unsigned integer
representing the delay period in milliseconds, and the second parameter is a callable
object returned by std::bind
. The DelayQueue gaurantees you that it won't start
execute the specified task after the configured amount of time.
You can also specify class member functions as tasks. For example, for a class member
function Foo::task
, you use std::bind(&Foo::task, ...)
to create the collable
object that a delay queue takes.
TBD
TBD