()
| 136 | } |
| 137 | |
| 138 | func (conn *WslConn) Close() error { |
| 139 | defer conn.FireConnChangeEvent() |
| 140 | conn.WithLock(func() { |
| 141 | if conn.Status == Status_Connected || conn.Status == Status_Connecting { |
| 142 | // if status is init, disconnected, or error don't change it |
| 143 | conn.Status = Status_Disconnected |
| 144 | } |
| 145 | conn.close_nolock() |
| 146 | }) |
| 147 | // we must wait for the waiter to complete |
| 148 | startTime := time.Now() |
| 149 | for conn.HasWaiter.Load() { |
| 150 | time.Sleep(10 * time.Millisecond) |
| 151 | if time.Since(startTime) > 2*time.Second { |
| 152 | return fmt.Errorf("timeout waiting for waiter to complete") |
| 153 | } |
| 154 | } |
| 155 | return nil |
| 156 | } |
| 157 | |
| 158 | func (conn *WslConn) close_nolock() { |
| 159 | // does not set status (that should happen at another level) |
no test coverage detected