Skip to content

Commit

Permalink
Merge pull request #20 from embano1/issue-14
Browse files Browse the repository at this point in the history
Improve Stream documentation
  • Loading branch information
embano1 committed Jan 17, 2022
2 parents d999022 + 34b6a62 commit f688f35
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const (
streamBackoffInterval = time.Millisecond * 10
)

// Stream is an iterator to stream records in order from a log
// Stream is an iterator to stream records in order from a log. It must only be
// used within the same goroutine.
type Stream struct {
ctx context.Context
log *Log
Expand All @@ -19,11 +20,11 @@ type Stream struct {
err error
}

// Next returns the next Record, but only if ok is true. If ok is false, the
// iterator was stopped and any subsequent calls will return an invalid record
// and false.
// Next blocks until the next Record is available. ok is true if the iterator
// has not stopped, otherwise ok is false and any subsequent calls return an
// invalid record and false.
//
// The caller must consult Err() which error, if any, caused stopping the error.
// The caller must consult Err() which error caused stopping the error.
func (s *Stream) Next() (r Record, ok bool) {
for {
if s.done {
Expand Down Expand Up @@ -54,9 +55,8 @@ func (s *Stream) Next() (r Record, ok bool) {
}
}

// Err returns the first error, if any, that has ocurred during streaming. When
// the stream iterator is stopped this method should be called to inspect
// whether the iterator was stopped due to an error.
// Err returns the first error that has ocurred during streaming. This method
// should be called to inspect the error that caused stopping the iterator.
func (s *Stream) Err() error {
return s.err
}
Expand All @@ -65,6 +65,9 @@ func (s *Stream) Err() error {
// start offset. If the start offset is in the future, stream will continuously
// poll until this offset is written.
//
// Use Stream.Next() to read from the stream. See the example for how to use
// this API.
//
// The returned stream iterator must only be used within the same goroutine.
func (l *Log) Stream(ctx context.Context, start Offset) Stream {
return Stream{
Expand Down

0 comments on commit f688f35

Please sign in to comment.