Branch data Line data Source code
1 : : // SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
2 : : // SPDX-FileCopyrightText: 2021 Evan Welsh <contact@evanwelsh.com>
3 : :
4 : : #pragma once
5 : :
6 : : #include <config.h>
7 : :
8 : : #include <memory>
9 : :
10 : : #include <glib.h>
11 : :
12 : : #include <js/TypeDecls.h>
13 : :
14 : : #include "gjs/auto.h"
15 : :
16 : : class GjsContextPrivate;
17 : :
18 : : namespace Gjs {
19 : :
20 : : using AutoMainContext = AutoPointer<GMainContext, GMainContext,
21 : 506 : g_main_context_unref, g_main_context_ref>;
22 : :
23 : : /**
24 : : * PromiseJobDispatcher:
25 : : *
26 : : * A class which wraps a custom GSource and handles associating it with a
27 : : * GMainContext. While it is running, it will attach the source to the main
28 : : * context so that promise jobs are run at the appropriate time.
29 : : */
30 : : class PromiseJobDispatcher {
31 : : class Source;
32 : : // The thread-default GMainContext
33 : : AutoMainContext m_main_context;
34 : : // The custom source.
35 : : std::unique_ptr<Source> m_source;
36 : :
37 : : public:
38 : : explicit PromiseJobDispatcher(GjsContextPrivate*);
39 : : ~PromiseJobDispatcher();
40 : :
41 : : /**
42 : : * PromiseJobDispatcher::start:
43 : : *
44 : : * Starts (or resumes) dispatching jobs from the promise job queue.
45 : : */
46 : : void start();
47 : :
48 : : /**
49 : : * PromiseJobDispatcher::stop:
50 : : *
51 : : * Stops dispatching jobs from the promise job queue.
52 : : */
53 : : void stop();
54 : :
55 : : /**
56 : : * PromiseJobDispatcher::is_running:
57 : : *
58 : : * Returns: Whether the dispatcher is currently running.
59 : : */
60 : : bool is_running();
61 : : };
62 : :
63 : : }; // namespace Gjs
64 : :
65 : : bool gjs_define_native_promise_stuff(JSContext*,
66 : : JS::MutableHandleObject module);
|