[gjs/ewlsh/implicit-mainloop: 2/4] (review and squash) Try a different name for PromiseJobQueueTask




commit 758a95966f9f670518cf441e50e02a53dcf85410
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Oct 16 10:21:42 2021 -0700

    (review and squash) Try a different name for PromiseJobQueueTask

 gjs/context-private.h |  2 +-
 gjs/context.cpp       | 12 ++++++------
 gjs/promise.cpp       | 14 +++++++-------
 gjs/promise.h         | 18 +++++++++---------
 4 files changed, 23 insertions(+), 23 deletions(-)
---
diff --git a/gjs/context-private.h b/gjs/context-private.h
index 776b919e..b8dffba2 100644
--- a/gjs/context-private.h
+++ b/gjs/context-private.h
@@ -79,7 +79,7 @@ class GjsContextPrivate : public JS::JobQueue {
     std::vector<std::string> m_args;
 
     JobQueueStorage m_job_queue;
-    Gjs::PromiseJobQueueTask m_promise_queue_task;
+    Gjs::PromiseJobDispatcher m_dispatcher;
 
     std::vector<std::pair<DestroyNotify, void*>> m_destroy_notifications;
     std::vector<Gjs::Closure::Ptr> m_async_closures;
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 461f3a65..644f7f42 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -535,7 +535,7 @@ GjsContextPrivate::GjsContextPrivate(JSContext* cx, GjsContext* public_context)
     : m_public_context(public_context),
       m_cx(cx),
       m_owner_thread(std::this_thread::get_id()),
-      m_promise_queue_task(this),
+      m_dispatcher(this),
       m_environment_preparer(cx) {
     JS_SetGCCallback(
         cx,
@@ -900,15 +900,15 @@ bool GjsContextPrivate::should_exit(uint8_t* exit_code_p) const {
 }
 
 void GjsContextPrivate::start_draining_job_queue(void) {
-    gjs_debug(GJS_DEBUG_CONTEXT, "Starting promise job queue task");
-    m_promise_queue_task.start();
+    gjs_debug(GJS_DEBUG_CONTEXT, "Starting promise job dispatcher");
+    m_dispatcher.start();
 }
 
 void GjsContextPrivate::stop_draining_job_queue(void) {
     m_draining_job_queue = false;
 
-    gjs_debug(GJS_DEBUG_CONTEXT, "Stopping promise job queue task");
-    m_promise_queue_task.stop();
+    gjs_debug(GJS_DEBUG_CONTEXT, "Stopping promise job dispatcher");
+    m_dispatcher.stop();
 }
 
 JSObject* GjsContextPrivate::getIncumbentGlobal(JSContext* cx) {
@@ -937,7 +937,7 @@ bool GjsContextPrivate::enqueuePromiseJob(JSContext* cx [[maybe_unused]],
     }
 
     JS::JobQueueMayNotBeEmpty(m_cx);
-    m_promise_queue_task.start();
+    m_dispatcher.start();
     return true;
 }
 
diff --git a/gjs/promise.cpp b/gjs/promise.cpp
index ce388c12..e63f3558 100644
--- a/gjs/promise.cpp
+++ b/gjs/promise.cpp
@@ -18,7 +18,7 @@ namespace Gjs {
 /**
  * @brief a custom GSource which handles draining our job queue.
  */
-class PromiseJobQueueTask::Source : public GSource {
+class PromiseJobDispatcher::Source : public GSource {
     // The private GJS context this source runs within.
     GjsContextPrivate* m_gjs;
     // The main context this source attaches to.
@@ -95,7 +95,7 @@ class PromiseJobQueueTask::Source : public GSource {
     void reset() { g_cancellable_reset(m_cancellable); }
 };
 
-GSourceFuncs PromiseJobQueueTask::Source::source_funcs = {
+GSourceFuncs PromiseJobDispatcher::Source::source_funcs = {
     [](GSource* source, int* timeout) {
         return static_cast<Source*>(source)->prepare(timeout);
     },
@@ -106,21 +106,21 @@ GSourceFuncs PromiseJobQueueTask::Source::source_funcs = {
     [](GSource* source) { static_cast<Source*>(source)->~Source(); },
 };
 
-PromiseJobQueueTask::PromiseJobQueueTask(GjsContextPrivate* gjs)
+PromiseJobDispatcher::PromiseJobDispatcher(GjsContextPrivate* gjs)
     // Acquire a guaranteed reference to this thread's default main context
     : m_main_context(g_main_context_ref_thread_default()),
       // Create and reference our custom GSource
       m_source(std::make_unique<Source>(gjs, m_main_context)) {}
 
-PromiseJobQueueTask::~PromiseJobQueueTask() {
+PromiseJobDispatcher::~PromiseJobDispatcher() {
     g_source_destroy(m_source.get());
 }
 
-bool PromiseJobQueueTask::is_running() {
+bool PromiseJobDispatcher::is_running() {
     return !!g_source_get_context(m_source.get());
 }
 
-void PromiseJobQueueTask::start() {
+void PromiseJobDispatcher::start() {
     // Reset the cancellable
     m_source->reset();
 
@@ -131,6 +131,6 @@ void PromiseJobQueueTask::start() {
     g_source_attach(m_source.get(), m_main_context);
 }
 
-void PromiseJobQueueTask::stop() { m_source->cancel(); }
+void PromiseJobDispatcher::stop() { m_source->cancel(); }
 
 };  // namespace Gjs
diff --git a/gjs/promise.h b/gjs/promise.h
index 193fbbdb..8fec2aeb 100644
--- a/gjs/promise.h
+++ b/gjs/promise.h
@@ -20,11 +20,11 @@ using GjsAutoMainContext =
 namespace Gjs {
 
 /**
- * @brief A class which wraps a custom GSource and handles
- * associating it with a main context. All memory is handled,
- * so this class is safe to use without raw pointers.
+ * @brief A class which wraps a custom GSource and handles associating it with a
+ * GMainContext. While it is running, it will attach the source to the main
+ * context so that promise jobs are run at the appropriate time.
  */
-class PromiseJobQueueTask {
+class PromiseJobDispatcher {
     class Source;
     // The thread-default GMainContext
     GjsAutoMainContext m_main_context;
@@ -32,21 +32,21 @@ class PromiseJobQueueTask {
     std::unique_ptr<Source> m_source;
 
  public:
-    explicit PromiseJobQueueTask(GjsContextPrivate*);
-    ~PromiseJobQueueTask();
+    explicit PromiseJobDispatcher(GjsContextPrivate*);
+    ~PromiseJobDispatcher();
 
     /**
-     * @brief Start (or restart) the task
+     * @brief Start (or resume) dispatching jobs from the promise job queue
      */
     void start();
 
     /**
-     * @brief Stop the task
+     * @brief Stop dispatching
      */
     void stop();
 
     /**
-     * @brief whether the task is currently running in the associated context
+     * @brief Whether the dispatcher is currently running
      */
     bool is_running();
 };


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]