From b8d59e4dd96463836b2babab7bb171434efaed92 Mon Sep 17 00:00:00 2001 From: John Delavega Date: Mon, 19 Aug 2019 17:07:17 -0700 Subject: [PATCH] Updated test apps cmd/listen... to continue Listening when event fails (#229) added comments in db/event_ref.go --- cmd/listen/main.go | 5 ++++- cmd/listen2/main.go | 10 ++++++++-- db/event_ref.go | 2 ++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cmd/listen/main.go b/cmd/listen/main.go index 65a9c85b..a98213b9 100644 --- a/cmd/listen/main.go +++ b/cmd/listen/main.go @@ -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()) diff --git a/cmd/listen2/main.go b/cmd/listen2/main.go index 4d8ca92d..d0a70fff 100644 --- a/cmd/listen2/main.go +++ b/cmd/listen2/main.go @@ -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) @@ -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()) diff --git a/db/event_ref.go b/db/event_ref.go index ac2f58e9..41f5125e 100644 --- a/db/event_ref.go +++ b/db/event_ref.go @@ -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 { @@ -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)