File: IdleEvent.hxx

package info (click to toggle)
mpd 0.24.2-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 10,764 kB
  • sloc: cpp: 75,446; python: 1,367; xml: 628; perl: 469; java: 289; sh: 286; ansic: 235; makefile: 106
file content (42 lines) | stat: -rw-r--r-- 855 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// SPDX-License-Identifier: BSD-2-Clause
// author: Max Kellermann <max.kellermann@gmail.com>

#pragma once

#include "DeferEvent.hxx"

class EventLoop;

/**
 * An event that runs when the EventLoop has become idle, before
 * waiting for more events.
 *
 * This class is not thread-safe, all methods must be called from the
 * thread that runs the #EventLoop, except where explicitly documented
 * as thread-safe.
 */
class IdleEvent final {
	DeferEvent event;

	using Callback = BoundMethod<void() noexcept>;

public:
	IdleEvent(EventLoop &_loop, Callback _callback) noexcept
		:event(_loop, _callback) {}

	auto &GetEventLoop() const noexcept {
		return event.GetEventLoop();
	}

	bool IsPending() const noexcept {
		return event.IsPending();
	}

	void Schedule() noexcept {
		event.ScheduleIdle();
	}

	void Cancel() noexcept {
		event.Cancel();
	}
};