Skip to content

Commit

Permalink
Expand documentation for *Iter.Next (#163)
Browse files Browse the repository at this point in the history
The documentation now explains the difference between calling Err and
Close after Next returns false.

The example code has been expanded to include checking for timeout.
  • Loading branch information
jefferickson authored and domodwyer committed May 21, 2018
1 parent bd62d93 commit 48a27cc
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -4265,16 +4265,21 @@ func (iter *Iter) Timeout() bool {
//
// Next returns true if a document was successfully unmarshalled onto result,
// and false at the end of the result set or if an error happened.
// When Next returns false, the Err method should be called to verify if
// there was an error during iteration, and the Timeout method to verify if the
// false return value was caused by a timeout (no available results).
// When Next returns false, either the Err method or the Close method should be
// called to verify if there was an error during iteration. While both will
// return the error (or nil), Close will also release the cursor on the server.
// The Timeout method may also be called to verify if the false return value
// was caused by a timeout (no available results).
//
// For example:
//
// iter := collection.Find(nil).Iter()
// for iter.Next(&result) {
// fmt.Printf("Result: %v\n", result.Id)
// }
// if iter.Timeout() {
// // react to timeout
// }
// if err := iter.Close(); err != nil {
// return err
// }
Expand Down

0 comments on commit 48a27cc

Please sign in to comment.