diff options
| author | ruki <[email protected]> | 2025-11-03 22:52:09 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-11-07 15:01:56 +0800 |
| commit | 7fc086de45783207a760e16b6b2b6a7f2e56a915 (patch) | |
| tree | 65949d7a492c001c42e0aa11bea81925d4512040 | |
| parent | 946da09bfffbf9193242d4d0ea39215925e6e379 (diff) | |
optimize detach async task
| -rw-r--r-- | xmake/core/base/private/async_task.lua | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/xmake/core/base/private/async_task.lua b/xmake/core/base/private/async_task.lua index a6116c5a0..d90579bc1 100644 --- a/xmake/core/base/private/async_task.lua +++ b/xmake/core/base/private/async_task.lua @@ -142,7 +142,14 @@ function async_task.cp(srcpath, dstpath, opt) srcpath = path.absolute(tostring(srcpath)) dstpath = path.absolute(tostring(dstpath)) task_queue:push({kind = "cp", srcpath = srcpath, dstpath = dstpath}) - task_event:post() + if opt.detach then + -- We cache some tasks before executing them to avoid frequent thread switching. + if task_queue:size() > 10 then + task_event:post() + end + else + task_event:post() + end return true end @@ -160,7 +167,14 @@ function async_task.rm(filepath, opt) -- post task filepath = path.absolute(tostring(filepath)) task_queue:push({kind = "rm", filepath = filepath}) - task_event:post() + if opt.detach then + -- We cache some tasks before executing them to avoid frequent thread switching. + if task_queue:size() > 10 then + task_event:post() + end + else + task_event:post() + end return true end @@ -178,7 +192,14 @@ function async_task.rmdir(dir, opt) -- post task dir = path.absolute(tostring(dir)) task_queue:push({kind = "rmdir", dir = dir}) - task_event:post() + if opt.detach then + -- We cache some tasks before executing them to avoid frequent thread switching. + if task_queue:size() > 10 then + task_event:post() + end + else + task_event:post() + end return true end |
