当前位置: 首页>>代码示例>>Golang>>正文


Golang Sequencer.Error方法代码示例

本文整理汇总了Golang中code/google/com/p/rog-go/new9p/seq.Sequencer.Error方法的典型用法代码示例。如果您正苦于以下问题:Golang Sequencer.Error方法的具体用法?Golang Sequencer.Error怎么用?Golang Sequencer.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在code/google/com/p/rog-go/new9p/seq.Sequencer的用法示例。


在下文中一共展示了Sequencer.Error方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: readFile

func (t *traverser) readFile(sq *seq.Sequencer, fid *g9pc.NsFile, path string) {
	t.printf("readFile %s", path)
	sq, results := sq.Subsequencer("readFile")
	go func() {
		_, ok := <-results // open
		if !ok {
			t.printf("cannot open %s: %v", path, sq.Error())
			return
		}
		<-results // stream
		_, ok = <-results
		if ok {
			panic("expected closed")
		}
		sq.Result(seq.StringResult("readFile"), sq.Error())
	}()
	sq.Do(fid.File(), seq.OpenReq{g9p.OREAD})
	rd := fid.SeqReadStream(sq, 20, 8192)
	tot, _ := io.Copy(nullWriter{}, rd)
	t.printf("%10d %s", tot, path)
	sq.Do(nil, nil)
}
开发者ID:zxpbenson,项目名称:rog-go,代码行数:22,代码来源:cl.go

示例2: SeqReadStream

func (nsf *NsFile) SeqReadStream(sq *seq.Sequencer, nreqs, iounit int) io.ReadCloser {
	cr := &streamReader{
		c:     make(chan readResult, 1),
		reply: make(chan bool),
	}
	sq, results := sq.Subsequencer("stream reader")
	buf := make([]byte, nreqs*iounit)
	bufs := make(chan []byte, nreqs)
	for i := 0; i < nreqs; i++ {
		bufs <- buf[0:iounit]
		buf = buf[iounit:]
	}
	buf = nil
	var q safeQueue
	done := make(chan bool)

	// Stream requests.
	go func() {
		f := nsf.File()
		offset := int64(0)
		for {
			b, ok := <-bufs
			if !ok {
				break
			}
			q.Put(b)
			log.Printf("stream doer: read %v", offset)
			sq.Do(f, seq.ReadReq{b, offset})
			offset += int64(len(b))
		}
		log.Printf("stream doer: do(nil, nil)")
		sq.Do(nil, nil)
		done <- true
	}()

	// Stream replies on demand from the streamReader.
	go func() {
		readerClosed := false
		for r := range results {
			log.Printf("stream: got result %#v (chan %p)\n", r, results)
			b := q.Get().([]byte)
			cr.c <- readResult{b[0:r.(seq.ReadResult).Count], nil}
			if !<-cr.reply {
				readerClosed = true
				break
			}
			bufs <- b
		}
		log.Printf("stream: closed")
		// Stop as many requests as possible from being sent.
		// If we implemented flush, we would flush the request now.
	loop:
		for {
			select {
			case <-bufs:
			default:
				break loop
			}
		}
		close(bufs)

		// Absorb and ignore any extra replies.
		for r := range results {
			log.Printf("stream: aborbing extra: %#v\n", r)
		}
		<-done

		err := sq.Error()
		if !readerClosed {
			log.Printf("stream: sending error to reader")
			if err == nil {
				err = io.EOF
			}
			cr.c <- readResult{nil, err}
		}
		log.Printf("stream: yielding result, err %#v\n", err)
		sq.Result(seq.StringResult("SeqReadStream"), err)
	}()
	return cr
}
开发者ID:juanman2,项目名称:dot-emacs,代码行数:80,代码来源:stream.go


注:本文中的code/google/com/p/rog-go/new9p/seq.Sequencer.Error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。