Пример #1
0
func TestDrainer(t *testing.T) {
	Convey("Given I have a context", t, func() {
		context := rivers.NewContext()

		Convey("And a stream of data", func() {
			in, out := stream.New(2)
			out <- 1
			out <- 2
			close(out)

			Convey("When I apply the drainer consumer", func() {
				consumer := consumers.Drainer()
				consumer.Attach(context)
				consumer.Consume(in)

				Convey("Then the stream is drained", func() {
					data, opened := <-in
					So(data, ShouldBeNil)
					So(opened, ShouldBeFalse)
				})
			})
		})
	})
}
Пример #2
0
func (pipeline *Pipeline) Drain() error {
	return pipeline.Then(consumers.Drainer())
}