func BenchClient(b *testing.B, c chan bool, sender libchan.Sender, sendFunc BenchMessageSender, count int) { defer close(c) for i := 0; i < count; i++ { sendFunc(i, sender) } err := sender.Close() if err != nil { b.Fatalf("Error closing sender: %s", err) } }
func (c *channel) copySender(val libchan.Sender) (libchan.Sender, error) { recv, send, err := c.CreateNestedReceiver() if err != nil { return nil, err } go func() { libchan.Copy(val, recv) val.Close() }() return send, nil }
func (c *channel) copySendChannel(send libchan.Sender) (*channel, error) { recv, sendCopy, err := c.CreateNestedReceiver() if err != nil { return nil, err } // Start copying into sender go func() { libchan.Copy(send, recv) send.Close() }() return sendCopy.(*channel), nil }
func BenchProxy(b *testing.B, c chan bool, sender libchan.Sender, receiver libchan.Receiver, count int) { defer close(c) n, err := libchan.Copy(sender, receiver) if err != nil { b.Errorf("Error proxying: %s", err) } err = sender.Close() if err != nil { b.Errorf("Error closing sender: %s", err) } if n != count { b.Errorf("Wrong proxy count\n\tExpected: %d\n\tActual: %d", count, n) } }