Skip to content

Better API for Watch / SSE Streaming #2

Description

@ereyes01

Currently Watch accepts a stop channel and returns an event channel. I'd like to make a simpler API that emulates bufio.Scanner. This should wrap the existing implementation to preserve binary compatibility, and to not break users who might need to select on multiple watchers.

Below is an example of what the new API would look like:

Initialize a watcher, and clean it up when we're done with it:

watcher, err := client.NewWatcher(unmarshaller)
if err != nil {
    // handle error
}
defer watcher.Close()

Iterate through events, and handle errors:

for watcher.Listen() {
    if err := watcher.ParseError(); err != nil {
        log.Println("Malformed event: ", err)
    }

    event := watcher.Event()
    // process event
}

if err := watcher.Error(); err != nil {
    // handle error
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions