Skip to content

Commit

Permalink
Updated test apps cmd/listen... to continue Listening when event fails (
Browse files Browse the repository at this point in the history
#229)

added comments in db/event_ref.go
  • Loading branch information
johndelavega committed Aug 20, 2019
1 parent dadd193 commit b8d59e4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion cmd/listen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ func main() {
event, err := iter.Next()

if err != nil {
break
// Handle error here based on specific usecase
// We can continue Listening
log.Printf("%v\n", err)
continue // go back to beginning of for loop
}

fmt.Printf("client app | Ref Path: %s | event.Path %s | event.Snapshot() = %v\n", ref.Path, event.Path, event.Snapshot())
Expand Down
10 changes: 8 additions & 2 deletions cmd/listen2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ func main() {
event, err := iter.Next()

if err != nil {
break
// Handle error here based on specific usecase
// We can continue Listening
log.Printf("%v\n", err)
continue // go back to beginning of for loop
}

err = event.Unmarshal(&key)
Expand Down Expand Up @@ -136,7 +139,10 @@ func main() {
event, err := iter2.Next()

if err != nil {
break
// Handle error here based on specific usecase
// We can continue Listening
log.Printf("%v\n", err)
continue // go back to beginning of for loop
}

fmt.Printf("2nd Listener | Ref Path: %s | event.Path %s | event.Snapshot() = %v\n", ref2.Path, event.Path, event.Snapshot())
Expand Down
2 changes: 2 additions & 0 deletions db/event_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func (r *Ref) Listen(ctx context.Context) (*SnapshotIterator, error) {

resp, err := r.sendListen(ctx, "GET", opts...)

// This is temporary true in case initialization fails
done := true

if err != nil {
Expand All @@ -50,6 +51,7 @@ func (r *Ref) Listen(ctx context.Context) (*SnapshotIterator, error) {
return &SnapshotIterator{done: &done}, err
}

// Initialization passed, we can continue with Listening
done = false
go r.startListeningWithReconnect(ctx, opts, resp, &done, sseDataChan)

Expand Down

0 comments on commit b8d59e4

Please sign in to comment.