Example #1
0
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)
	}
}
Example #2
0
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
}
Example #3
0
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
}
Example #4
0
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)
	}
}