File tree Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ type Decoder struct {
3131 OnAlert func (* EventAlert )
3232 OnError func (* EventError )
3333 OnUnknown func (event , data []byte )
34+ OnDone func ()
3435}
3536
3637func (rr Decoder ) ReadAll (r io.Reader ) error {
@@ -125,6 +126,9 @@ func (rr Decoder) ReadAll(r io.Reader) error {
125126 rr .OnError (& d )
126127 } else if bytes .Equal (event , []byte ("done" )) {
127128 // Always the last event
129+ if rr .OnDone != nil {
130+ rr .OnDone ()
131+ }
128132 break
129133 } else {
130134 if rr .OnUnknown == nil {
Original file line number Diff line number Diff line change @@ -106,6 +106,11 @@ func TestDecoder(t *testing.T) {
106106 OnUnknown : func (event , data []byte ) {
107107 t .Fatalf ("got unexpected event: %s %s" , event , data )
108108 },
109+ OnDone : func () {
110+ if len (got ) != len (want ) {
111+ t .Fatalf ("OnDone was called before the last event was processed." )
112+ }
113+ },
109114 }.ReadAll (resp .Body )
110115 if err != nil {
111116 t .Fatal (err )
You can’t perform that action at this time.
0 commit comments