Skip to content

Commit

Permalink
Merge pull request #40 from CovenantSQL/master
Browse files Browse the repository at this point in the history
Expose Stream.die via Stream.GetDieCh for canceling running golang RPC func
  • Loading branch information
xtaci authored Dec 5, 2018
2 parents f19baee + 9a59621 commit 6cf098d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ func TestEcho(t *testing.T) {
session.Close()
}

func TestGetDieCh(t *testing.T) {
cs, ss, err := getSmuxStreamPair()
if err != nil {
t.Fatal(err)
}
defer ss.Close()
dieCh := ss.GetDieCh()
go func() {
select {
case <-dieCh:
case <-time.Tick(time.Second):
t.Fatal("wait die chan timeout")
}
}()
cs.Close()
}

func TestSpeed(t *testing.T) {
_, stop, cli, err := setupServer(t)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ func (s *Stream) Close() error {
}
}

// GetDieCh returns a readonly chan which can be readable
// when the stream is to be closed.
func (s *Stream) GetDieCh() <-chan struct{} {
return s.die
}

// SetReadDeadline sets the read deadline as defined by
// net.Conn.SetReadDeadline.
// A zero time value disables the deadline.
Expand Down

0 comments on commit 6cf098d

Please sign in to comment.