From aebd32136b74ae9cbec239d02ee1943930be7297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fan=20Can=20Bak=C4=B1r?= Date: Fri, 22 Dec 2023 13:26:46 +0300 Subject: [PATCH] use predicate --- process/process.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/process/process.go b/process/process.go index c33ece9..00fcfba 100644 --- a/process/process.go +++ b/process/process.go @@ -6,18 +6,18 @@ import ( ) // CloseProcesses part -func CloseProcesses(filter func(process *ps.Process) bool, skipPids map[int32]struct{}) { +func CloseProcesses(predicate func(process *ps.Process) bool, skipPids map[int32]struct{}) { processes, err := ps.Processes() if err != nil { return } for _, process := range processes { - // skip non-chrome processes - if !IsChromeProcess(process) { + // skip processes that do not satisfy the predicate + if !predicate(process) { continue } - // skip chrome processes that were already running + // skip processes that are in the skip list if _, ok := skipPids[process.Pid]; ok { continue } @@ -26,11 +26,11 @@ func CloseProcesses(filter func(process *ps.Process) bool, skipPids map[int32]st } // FindProcesses finds chrome process running on host -func FindProcesses(filter func(process *ps.Process) bool) map[int32]struct{} { +func FindProcesses(predicate func(process *ps.Process) bool) map[int32]struct{} { processes, _ := ps.Processes() list := make(map[int32]struct{}) for _, process := range processes { - if filter(process) { + if predicate(process) { list[process.Pid] = struct{}{} if ppid, err := process.Ppid(); err == nil { list[ppid] = struct{}{}