return bool if stream exists in StreamsMap GetStream

This commit is contained in:
Marten Seemann 2016-08-05 14:11:36 +07:00
parent b3e76770de
commit c3dcb649c7
2 changed files with 9 additions and 9 deletions

View file

@ -19,14 +19,14 @@ func newStreamsMap() *streamsMap {
}
}
func (m *streamsMap) GetStream(id protocol.StreamID) (*stream, error) {
func (m *streamsMap) GetStream(id protocol.StreamID) (*stream, bool) {
m.mutex.RLock()
s, ok := m.streams[id]
m.mutex.RUnlock()
if !ok {
return nil, fmt.Errorf("unknown stream: %d", id)
return nil, false
}
return s, nil
return s, true
}
func (m *streamsMap) PutStream(s *stream) error {

View file

@ -16,8 +16,8 @@ var _ = Describe("Streams Map", func() {
})
It("returns an error for non-existant streams", func() {
_, err := m.GetStream(1)
Expect(err).To(MatchError("unknown stream: 1"))
_, exists := m.GetStream(1)
Expect(exists).To(BeFalse())
})
It("returns nil for previously existing streams", func() {
@ -25,8 +25,8 @@ var _ = Describe("Streams Map", func() {
Expect(err).NotTo(HaveOccurred())
err = m.RemoveStream(1)
Expect(err).NotTo(HaveOccurred())
s, err := m.GetStream(1)
Expect(err).NotTo(HaveOccurred())
s, exists := m.GetStream(1)
Expect(exists).To(BeTrue())
Expect(s).To(BeNil())
})
@ -38,8 +38,8 @@ var _ = Describe("Streams Map", func() {
It("stores streams", func() {
err := m.PutStream(&stream{streamID: 5})
Expect(err).NotTo(HaveOccurred())
s, err := m.GetStream(5)
Expect(err).NotTo(HaveOccurred())
s, exists := m.GetStream(5)
Expect(exists).To(BeTrue())
Expect(s.streamID).To(Equal(protocol.StreamID(5)))
})