1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 03:50:08 +02:00

👌 Add comments about concurrency

This commit is contained in:
2023-01-06 13:07:02 +01:00
parent 291d20b2b3
commit 6d52992c9d
3 changed files with 18 additions and 6 deletions

View File

@ -62,10 +62,12 @@ class HomebrewService: Decodable, Equatable, Hashable {
hasher.combine(name)
hasher.combine(service_name)
hasher.combine(pid)
hasher.combine(status)
}
static func == (lhs: HomebrewService, rhs: HomebrewService) -> Bool {
return lhs.name == rhs.name
&& lhs.service_name == rhs.service_name
&& lhs.pid == rhs.pid
&& lhs.status == rhs.status
}

View File

@ -50,7 +50,8 @@ public class ServiceWrapper: ObservableObject, Identifiable, Hashable {
}
public static func == (lhs: ServiceWrapper, rhs: ServiceWrapper) -> Bool {
return lhs.service == rhs.service && lhs.formula == rhs.formula
return lhs.service == rhs.service
&& lhs.formula == rhs.formula
}
public func hash(into hasher: inout Hasher) {

View File

@ -16,6 +16,11 @@ class ValetServicesManager: ServicesManager {
Task { await self.reloadServicesStatus() }
}
/**
This method allows us to reload the Homebrew services, but we run this command
twice (once for user services, and once for root services). Please note that
these two commands are executed concurrently.
*/
override func reloadServicesStatus() async {
await withTaskGroup(of: [HomebrewService].self, body: { group in
group.addTask {
@ -46,21 +51,25 @@ class ValetServicesManager: ServicesManager {
.filter({ return userServiceNames.contains($0.name) })
}
// Ensure both commands complete (but run concurrently)
for await services in group {
// For both groups (user and root services), set the service to the wrapper object
for service in services {
guard let wrapper = self[service.name] else {
break
}
wrapper.service = service
self[service.name]?.service = service
}
}
// Ensure that every wrapper is considered no longer busy
for wrapper in serviceWrappers {
wrapper.isBusy = false
}
// Broadcast that all services have been updated
self.broadcastServicesUpdated()
})
}
override func toggleService(named: String) async {
// TODO
}
}