浏览文件
process_wait.go
30 行 · 836 B历史下载| 1 | // SPDX-FileCopyrightText: Copyright The Lima Authors |
| 2 | // SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| 4 | package qemu |
| 5 | |
| 6 | import "sync" |
| 7 | |
| 8 | // watchQEMU reports process exit and network setup failures on the driver's |
| 9 | // existing wait channel. afterExit cancels setup and releases the netstack. |
| 10 | func watchQEMU(wait, configure func() error, afterExit func()) chan error { |
| 11 | // Each producer can publish once even when Start's caller has stopped |
| 12 | // receiving. Only the coordinator closes the channel, after both finish. |
| 13 | errors := make(chan error, 2) |
| 14 | var producers sync.WaitGroup |
| 15 | producers.Add(2) |
| 16 | go func() { |
| 17 | defer producers.Done() |
| 18 | err := wait() |
| 19 | afterExit() |
| 20 | errors <- err |
| 21 | }() |
| 22 | go func() { |
| 23 | defer producers.Done() |
| 24 | if err := configure(); err != nil { |
| 25 | errors <- err |
| 26 | } |
| 27 | }() |
| 28 | go func() { producers.Wait(); close(errors) }() |
| 29 | return errors |
| 30 | } |

