本文整理匯總了Golang中github.com/elves/elvish/parse.Pipeline.SourceText方法的典型用法代碼示例。如果您正苦於以下問題:Golang Pipeline.SourceText方法的具體用法?Golang Pipeline.SourceText怎麽用?Golang Pipeline.SourceText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/elves/elvish/parse.Pipeline
的用法示例。
在下文中一共展示了Pipeline.SourceText方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: pipeline
func (cp *compiler) pipeline(n *parse.Pipeline) OpFunc {
ops := cp.formOps(n.Forms)
return func(ec *EvalCtx) {
bg := n.Background
if bg {
ec = ec.fork("background job " + n.SourceText())
ec.intCh = nil
ec.background = true
if ec.Editor != nil {
// TODO: Redirect output in interactive mode so that the line
// editor does not get messed up.
}
}
nforms := len(ops)
var wg sync.WaitGroup
wg.Add(nforms)
errors := make([]Error, nforms)
var verdict bool
var nextIn *Port
// For each form, create a dedicated evalCtx and run asynchronously
for i, op := range ops {
newEc := ec.fork(fmt.Sprintf("form op %v", op))
if i > 0 {
newEc.ports[0] = nextIn
}
if i < nforms-1 {
// Each internal port pair consists of a (byte) pipe pair and a
// channel.
// os.Pipe sets O_CLOEXEC, which is what we want.
reader, writer, e := os.Pipe()
if e != nil {
throwf("failed to create pipe: %s", e)
}
ch := make(chan Value, pipelineChanBufferSize)
newEc.ports[1] = &Port{
File: writer, Chan: ch, CloseFile: true, CloseChan: true}
nextIn = &Port{
File: reader, Chan: ch, CloseFile: true, CloseChan: false}
}
thisOp := op
thisError := &errors[i]
isLast := i == nforms-1
go func() {
err := newEc.PEval(thisOp)
// Logger.Printf("closing ports of %s", newEc.context)
ClosePorts(newEc.ports)
if isLast {
verdict = newEc.verdict
}
*thisError = Error{err}
wg.Done()
}()
}
if bg {
// Background job, wait for form termination asynchronously.
go func() {
wg.Wait()
msg := "job " + n.SourceText() + " finished"
if !allok(errors) {
msg += ", errors = " + makeCompositeError(errors).Error()
}
if !verdict {
msg += ", pred = false"
}
if ec.Editor != nil {
m := ec.Editor.ActiveMutex()
m.Lock()
defer m.Unlock()
if ec.Editor.Active() {
ec.Editor.Notify("%s", msg)
} else {
ec.ports[2].File.WriteString(msg)
}
} else {
ec.ports[2].File.WriteString(msg)
}
}()
} else {
wg.Wait()
maybeThrow(makeCompositeError(errors))
ec.verdict = verdict
}
}
}