feat: make system calls more parallel (closes #160)

This commit is contained in:
louis.pontoise authored and lwouis committed 2020-03-10 14:00:37 +09:00
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()
}
}
+6 -7
View File
@@ -26,17 +26,16 @@ class Windows {
static func updateSpaces() {
let spacesMap = Spaces.allIdsAndIndexes()
for window in list {
list.forEachAsync { window in
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.spaceIndex = Spaces.currentSpaceIndex
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() {
for window in list {
list.forEachAsync { window in
window.refreshThumbnail()
}
}