github.com/searKing/golang/go@v1.2.74/container/stream/op/match/task.go (about) 1 // Copyright 2020 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package match 6 7 import ( 8 "context" 9 10 "github.com/searKing/golang/go/container/stream/op/terminal" 11 "github.com/searKing/golang/go/util/spliterator" 12 ) 13 14 type MatchTask struct { 15 terminal.TODOShortCircuitTask 16 17 op MatchOp 18 } 19 20 func NewMatchTask(op MatchOp, spliterator spliterator.Spliterator) *MatchTask { 21 matcher := &MatchTask{ 22 op: op, 23 } 24 matcher.WithSpliterator(spliterator) 25 matcher.SetDerived(matcher) 26 return matcher 27 } 28 29 func NewTaskFromParent(parent MatchTask, spliterator spliterator.Spliterator) *MatchTask { 30 matcher := &MatchTask{ 31 op: parent.op, 32 } 33 matcher.WithSpliterator(spliterator) 34 matcher.SetDerived(matcher) 35 return matcher 36 } 37 38 func (task MatchTask) MakeChild(spliterator spliterator.Spliterator) terminal.Task { 39 return NewTaskFromParent(task, spliterator) 40 } 41 42 func (task MatchTask) DoLeaf(ctx context.Context) terminal.Sink { 43 result := terminal.WrapAndCopyInto(ctx, task.op.MakeSink(), task.GetSpliterator()) 44 b := result.(*booleanTerminalSink).GetAndClearState() 45 if b == task.op.matchKind.ShortCircuitResult { 46 task.ShortCircuit(result) 47 } 48 return nil 49 }