mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-23 12:07:17 +00:00
98f8ccc561
* cmd for integration tests * cmd for integration tests
30 lines
360 B
Go
30 lines
360 B
Go
package common
|
|
|
|
import "errors"
|
|
|
|
var ErrStopped = errors.New("stopped")
|
|
|
|
func Stopped(ch <-chan struct{}) error {
|
|
if ch == nil {
|
|
return nil
|
|
}
|
|
select {
|
|
case <-ch:
|
|
return ErrStopped
|
|
default:
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func SafeClose(ch chan struct{}) {
|
|
if ch == nil {
|
|
return
|
|
}
|
|
select {
|
|
case <-ch:
|
|
// Channel was already closed
|
|
default:
|
|
close(ch)
|
|
}
|
|
}
|