a2f8605c66
Move the subscription context to Next. context.Context should generally never be stored in a struct because it makes that struct only valid while the context is valid. This is rarely obvious from the caller. Adds a forceClosed channel in place of the old context, and uses the new context as a way for the caller to stop the Subscription blocking. Remove some recursion out of bufferImte.Next. The caller is already looping so we can continue in that loop instead of recursing. This ensures currentItem is updated immediately (which probably does not matter in practice), and also removes the chance that we overflow the stack. NextNoBlock and FollowAfter do not need to handle bufferItem.Err, the caller already handles it. Moves filter to a method to simplify Next, and more explicitly separate filtering from looping. Also improve some godoc Only unwrap itemBuffer.Err when necessary
18 lines
342 B
Go
18 lines
342 B
Go
package stream
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestEvent_IsEndOfSnapshot(t *testing.T) {
|
|
e := Event{Payload: endOfSnapshot{}}
|
|
require.True(t, e.IsEndOfSnapshot())
|
|
|
|
t.Run("not EndOfSnapshot", func(t *testing.T) {
|
|
e := Event{Payload: endOfEmptySnapshot{}}
|
|
require.False(t, e.IsEndOfSnapshot())
|
|
})
|
|
}
|