コード例 #1
0
ファイル: util.go プロジェクト: sgichohi/go-stream
func NewDropOp() *mapper.Op {
	dropfn := func(input stream.Object, out mapper.Outputer) error {
		return nil
	}

	return mapper.NewOp(dropfn, "DropOp")
}
コード例 #2
0
ファイル: util.go プロジェクト: sgichohi/go-stream
func NewPassthruOp() *mapper.Op {
	fn := func(input stream.Object, out mapper.Outputer) error {
		out.Sending(1).Send(input)
		return nil
	}

	return mapper.NewOp(fn, "PassthruOp")
}
コード例 #3
0
ファイル: order_test.go プロジェクト: sgichohi/go-stream
func TestNoOrder(t *testing.T) {

	input := make(chan stream.Object)

	passthruFn := func(obj stream.Object, out mapper.Outputer) {
		out.Sending(1).Send(obj)
	}

	FirstOp := mapper.NewOp(passthruFn, "First PT no")
	FirstOp.SetIn(input)
	SecondOp := mapper.NewOp(passthruFn, "2nd PT no")

	ch := stream.NewChain()
	ch.Add(FirstOp)
	ch.Add(SecondOp)

	output := SecondOp.Out()
	ch.Start()

	go func() {
		for i := 0; i < 10000; i++ {
			input <- i
		}
	}()

	found := false
	for i := 0; i < 10000; i++ {
		val := <-output
		if val != i {
			found = true
		}
	}

	if !found {
		t.Error("Weird no out of order stuff found")
	}
	ch.Stop()
	ch.Wait()
}