本文整理匯總了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),