浏览文件
keepawake.go
22 行 · 467 B历史下载| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "log" |
| 6 | |
| 7 | "github.com/sylvinus/agent-vm/internal/keepawake" |
| 8 | ) |
| 9 | |
| 10 | func keepHostAwake(parent context.Context, logger *log.Logger) func() { |
| 11 | ctx, cancel := context.WithCancel(parent) |
| 12 | done := make(chan struct{}) |
| 13 | go func() { |
| 14 | defer close(done) |
| 15 | keepawake.Run(ctx, func(state keepawake.State) { |
| 16 | if state.Error != "" { |
| 17 | logger.Println("Host keep-awake unavailable:", state.Error) |
| 18 | } |
| 19 | }) |
| 20 | }() |
| 21 | return func() { cancel(); <-done } |
| 22 | } |

