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


Golang Sender.Send方法代码示例

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


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

示例1: NewQueue

func NewQueue(dst libchan.Sender, size int) *Queue {
	r, w := libchan.Pipe()
	q := &Queue{
		PipeSender: w,
		dst:        dst,
		ch:         make(chan *libchan.Message, size),
	}
	go func() {
		defer close(q.ch)
		for {
			msg, err := r.Receive(libchan.Ret)
			if err != nil {
				r.Close()
				return
			}
			q.ch <- msg
		}
	}()
	go func() {
		for msg := range q.ch {
			_, err := dst.Send(msg)
			if err != nil {
				r.Close()
				return
			}
		}
	}()
	return q
}
开发者ID:ndeloof,项目名称:libchan,代码行数:29,代码来源:queue.go

示例2: doEcho

func doEcho(sender libchan.Sender, timeout time.Duration) error {
	txt := "Hello world!"
	replyRecv, replySend := libchan.Pipe()

	req := Request{ER: (*EchoRequest)(&txt), Reply: replySend}

	err := sender.Send(req)
	if err != nil {
		replySend.Close()
		return err
	}

	var reply Reply
	err = replyRecv.Receive(&reply)
	if err != nil {
		return err
	}
	if reply.Code != CodeOK {
		return fmt.Errorf("%s", reply.Error)
	}
	if string(*reply.ER) != txt {
		return fmt.Errorf("echo returned bad message: '%s'", reply.ER)
	}
	return nil
}
开发者ID:kaaLabs15,项目名称:widuino,代码行数:25,代码来源:chancli.go

示例3: SendEvents

func SendEvents(ch chan FileEvent, sender libchan.Sender) error {
	for ev := range ch {
		if err := sender.Send(ev); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:lox,项目名称:binarystar,代码行数:8,代码来源:events.go

示例4: SendTo

func (r *receiver) SendTo(dst libchan.Sender) (int, error) {
	var n int
	for {
		var rm msgpack.RawMessage
		if err := r.Receive(&rm); err == io.EOF {
			break
		} else if err != nil {
			return n, err
		}

		if err := dst.Send(&rm); err != nil {
			return n, err
		}
		n++
	}
	return n, nil
}
开发者ID:zhaohaidao,项目名称:libchan,代码行数:17,代码来源:session.go

示例5: SendTo

func (c *channel) SendTo(dst libchan.Sender) (int, error) {
	if c.direction == outbound {
		return 0, ErrWrongDirection
	}
	var n int
	for {
		var rm msgpack.RawMessage
		if err := c.Receive(&rm); err == io.EOF {
			break
		} else if err != nil {
			return n, err
		}

		if err := dst.Send(&rm); err != nil {
			return n, err
		}
		n++
	}
	return n, nil
}
开发者ID:beibei1990,项目名称:libchan,代码行数:20,代码来源:session.go

示例6:

		time.Sleep(10 * time.Millisecond)

		db.Close()
		os.RemoveAll(dbDir)
	})

	It("responds to echo requests", func() {
		responseRecv, responseSend := libchan.Pipe()

		req := &EchoRequest{
			Cmd:   "echo",
			Text:  "Hello world!",
			Reply: responseSend,
		}

		err := clientSender.Send(req)
		Ω(err).ShouldNot(HaveOccurred())

		response := &EchoReply{}
		err = responseRecv.Receive(response)
		Ω(err).ShouldNot(HaveOccurred())

		//fmt.Println(response.Text)
		Ω(response.Text).Should(Equal(req.Text))
	})

	It("processes subscriptions", func() {
		// Create some initial messages
		now := time.Now().Unix()
		for i := 0; i < 10; i += 1 {
			m := database.RFMessage{At: now + int64(i), Group: byte(2 * i),
开发者ID:kaaLabs15,项目名称:widuino,代码行数:31,代码来源:chansrv_test.go


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