[gnome-music/wip/mschraal/asyncqueue-rework: 2/2] asyncqueue: Start as much tasks as allowed




commit 7121cdc416fda821aceb4a3499824a7596663bef
Author: Marinus Schraal <mschraal gnome org>
Date:   Sun Sep 26 12:03:29 2021 +0200

    asyncqueue: Start as much tasks as allowed
    
    Previously dispatch would add one task per call even if more allowed
    async slots were available.
    
    Fill out the available active pool slots instead.

 gnomemusic/asyncqueue.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
---
diff --git a/gnomemusic/asyncqueue.py b/gnomemusic/asyncqueue.py
index 7d8ca47dd..2b13c041d 100644
--- a/gnomemusic/asyncqueue.py
+++ b/gnomemusic/asyncqueue.py
@@ -82,10 +82,11 @@ class AsyncQueue(GObject.GObject):
     def _dispatch(self) -> bool:
         tick = time.time()
 
-        if len(self._async_pool) == 0:
-            self._timeout_id = 0
-            return GLib.SOURCE_REMOVE
-        elif len(self._async_active_pool) < self._max_async:
+        while len(self._async_active_pool) < self._max_async:
+            if len(self._async_pool) == 0:
+                self._timeout_id = 0
+                return GLib.SOURCE_REMOVE
+
             async_obj_id = list(self._async_pool.keys())[0]
             async_task_args = self._async_pool.pop(async_obj_id)
             async_obj = async_task_args[0]


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