-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcommon_test.go
More file actions
36 lines (31 loc) · 820 Bytes
/
common_test.go
File metadata and controls
36 lines (31 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package sshd
import (
"fmt"
"sync"
"time"
)
type errWGTimedOut struct {
to time.Duration
}
func (e errWGTimedOut) Error() string {
return fmt.Sprintf("WaitGroup wait timed out after %s", e.to)
}
// waitWithTimeout waits for wg.Done() until timeout expires. returns errWGTimedOut if timeout expired before wg.Done() returned, otherwise returns nil. this func is naturally leaky if wg.Done() never returns
func waitWithTimeout(wg *sync.WaitGroup, timeout time.Duration) error {
ch := make(chan struct{})
go func() {
defer close(ch)
wg.Wait()
}()
select {
case <-time.After(timeout):
return errWGTimedOut{to: timeout}
case <-ch:
return nil
}
}
// sshSessionOutput is the output from a *(golang.org/x/crypto/ssh).Session's Output() call
type sshSessionOutput struct {
outStr string
err error
}