feat: make system calls more parallel (closes #160)
This commit is contained in:
1 parent
e28c43f227
commit
a29b39fc87
2 files changed
+21
-7
No files matched your search
@@ -107,3 +107,18 @@ extension NSGridView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Array {
|
||||||
|
// forEach with each iteration run concurrently on the global queue
|
||||||
|
func forEachAsync(fn: @escaping (Element) -> Void) {
|
||||||
|
let group = DispatchGroup()
|
||||||
|
for element in self {
|
||||||
|
group.enter()
|
||||||
|
DispatchQueue.global(qos: .userInteractive).async(group: group) {
|
||||||
|
fn(element)
|
||||||
|
group.leave()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
group.wait()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,17 +26,16 @@ class Windows {
|
|||||||
|
|
||||||
static func updateSpaces() {
|
static func updateSpaces() {
|
||||||
let spacesMap = Spaces.allIdsAndIndexes()
|
let spacesMap = Spaces.allIdsAndIndexes()
|
||||||
for window in list {
|
list.forEachAsync { window in
|
||||||
let spaceIds = window.cgWindowId.spaces()
|
let spaceIds = window.cgWindowId.spaces()
|
||||||
guard spaceIds.count > 0 else { continue }
|
if spaceIds.count == 1 {
|
||||||
if spaceIds.count > 1 {
|
window.spaceId = spaceIds.first!
|
||||||
|
window.spaceIndex = spacesMap.first { $0.0 == spaceIds.first! }!.1
|
||||||
|
} else if spaceIds.count > 1 {
|
||||||
window.spaceId = Spaces.currentSpaceId
|
window.spaceId = Spaces.currentSpaceId
|
||||||
window.spaceIndex = Spaces.currentSpaceIndex
|
window.spaceIndex = Spaces.currentSpaceIndex
|
||||||
window.isOnAllSpaces = true
|
window.isOnAllSpaces = true
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
window.spaceId = spaceIds.first!
|
|
||||||
window.spaceIndex = spacesMap.first { $0.0 == spaceIds.first! }!.1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +58,7 @@ class Windows {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static func refreshAllThumbnails() {
|
static func refreshAllThumbnails() {
|
||||||
for window in list {
|
list.forEachAsync { window in
|
||||||
window.refreshThumbnail()
|
window.refreshThumbnail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user