Skip to content

Commit

Permalink
Fix context usage
Browse files Browse the repository at this point in the history
Actually use contexts like they should.
Fixes watchGGST() loop running at full speed.
This is what happens when you don't read the docs.

Fixes #23
  • Loading branch information
optix2000 committed Aug 8, 2021
1 parent ce01da1 commit 81974e1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,9 @@ func messageBox(message string) {
func watchGGST(noClose bool, ctx context.Context) {
var patchedPid uint32 = 1
var close bool = false
fastSleep, cancel := context.WithTimeout(ctx, 2*time.Second)
defer cancel()
slowSleep, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()

for {

select {
case <-ctx.Done():
return
Expand All @@ -100,14 +97,18 @@ func watchGGST(noClose bool, ctx context.Context) {
fmt.Println("Waiting for GGST process...")
patchedPid = 0
}
fastSleep.Done()
fastSleep, fastCancel := context.WithTimeout(ctx, 2*time.Second)
<-fastSleep.Done()
fastCancel()
continue
} else {
panic(err)
}
}
if pid == patchedPid {
slowSleep.Done()
slowSleep, slowCancel := context.WithTimeout(ctx, 10*time.Second)
<-slowSleep.Done()
slowCancel()
continue
}
time.Sleep(100 * time.Millisecond) // Give GGST some time to finish loading. EnumProcessModules() doesn't like modules changing while it's running.
Expand Down

0 comments on commit 81974e1

Please sign in to comment.