本文整理汇总了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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),