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




commit 871870adcbb27dccd72ea0c30ff1cbf244fa4f9d
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 f843ac7b0..546d6ba61 100644
--- a/gnomemusic/asyncqueue.py
+++ b/gnomemusic/asyncqueue.py
@@ -83,10 +83,11 @@ class AsyncQueue(GObject.GObject):
         result_id = 0
         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]