mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2026-03-26 22:20:06 +01:00
👌 Add comments about concurrency
This commit is contained in:
@@ -62,10 +62,12 @@ class HomebrewService: Decodable, Equatable, Hashable {
|
|||||||
hasher.combine(name)
|
hasher.combine(name)
|
||||||
hasher.combine(service_name)
|
hasher.combine(service_name)
|
||||||
hasher.combine(pid)
|
hasher.combine(pid)
|
||||||
|
hasher.combine(status)
|
||||||
}
|
}
|
||||||
|
|
||||||
static func == (lhs: HomebrewService, rhs: HomebrewService) -> Bool {
|
static func == (lhs: HomebrewService, rhs: HomebrewService) -> Bool {
|
||||||
return lhs.name == rhs.name
|
return lhs.name == rhs.name
|
||||||
|
&& lhs.service_name == rhs.service_name
|
||||||
&& lhs.pid == rhs.pid
|
&& lhs.pid == rhs.pid
|
||||||
&& lhs.status == rhs.status
|
&& lhs.status == rhs.status
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ public class ServiceWrapper: ObservableObject, Identifiable, Hashable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static func == (lhs: ServiceWrapper, rhs: ServiceWrapper) -> Bool {
|
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) {
|
public func hash(into hasher: inout Hasher) {
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ class ValetServicesManager: ServicesManager {
|
|||||||
Task { await self.reloadServicesStatus() }
|
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 {
|
override func reloadServicesStatus() async {
|
||||||
await withTaskGroup(of: [HomebrewService].self, body: { group in
|
await withTaskGroup(of: [HomebrewService].self, body: { group in
|
||||||
group.addTask {
|
group.addTask {
|
||||||
@@ -46,21 +51,25 @@ class ValetServicesManager: ServicesManager {
|
|||||||
.filter({ return userServiceNames.contains($0.name) })
|
.filter({ return userServiceNames.contains($0.name) })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure both commands complete (but run concurrently)
|
||||||
for await services in group {
|
for await services in group {
|
||||||
|
// For both groups (user and root services), set the service to the wrapper object
|
||||||
for service in services {
|
for service in services {
|
||||||
guard let wrapper = self[service.name] else {
|
self[service.name]?.service = service
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
wrapper.service = service
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure that every wrapper is considered no longer busy
|
||||||
for wrapper in serviceWrappers {
|
for wrapper in serviceWrappers {
|
||||||
wrapper.isBusy = false
|
wrapper.isBusy = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Broadcast that all services have been updated
|
||||||
self.broadcastServicesUpdated()
|
self.broadcastServicesUpdated()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func toggleService(named: String) async {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user