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




commit e356d3d0eaf34081d8064bd89a6600608177fac8
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 0f406727b..9d830c670 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]