DispatchQueue¶
Queues and executes arbitrary functions on a thread.
Declaration¶
namespace bdn {
class DispatchQueue
}
Types¶
- using Function = std::function<void()>
- using Clock = std::chrono::steady_clock
- using TimePoint = Clock::time_point
Creating a DispatchQueue Object¶
-
DispatchQueue(bool slave = false)
Constructs a dispatch queue. If
slaveisfalse(the default), creates and manages a thread for the dispatch queue. Ifslaveistrue, the queue will not create a thread on its own. This is handy if there is already a thread/run loop which should be integrated with the dispatch queue.
Dispatching Methods to the Queue¶
-
void dispatchSync(Function function)
Dispatches a
functionon the dispatch queue thread and waits for it to finish. -
void dispatchAsync(Function function)
Dispatches a
functionon the dispatch queue thread and returns immediately. -
template <> void dispatchAsyncDelayed(std::chrono::duration<> delay, Function function)
Dispatches a
functionto run on the dispatch queue thread after thedelay.
Creating Timers¶
-
template<> createTimer(std::chrono::duration<> interval, std::function<bool()> timer)
Creates a timer that will run
timerrepeatedly on the dispatch queue's thread everyintervaluntiltimerreturnsfalse.
Controlling the Queue's Internal Processing¶
-
void enter()
Starts processing synchronously until
cancelis called. Only allowed ifslavewas true during construction. -
void cancel()
Stops processing as soon as possible.
-
void executeSync()
Executes the next function scheduled on the queue and returns.