Пример #1
0
func NewQueue(dst beam.Sender, size int) *Queue {
	r, w := beam.Pipe()
	q := &Queue{
		PipeSender: w,
		dst:        dst,
		ch:         make(chan *beam.Message, size),
	}
	go func() {
		defer close(q.ch)
		for {
			msg, err := r.Receive(beam.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
0
// Function for forwarding a messgae including some minor error formatting
func forward(out beam.Sender, msg *beam.Message) (err error) {
	if _, err := out.Send(msg); err != nil {
		return fmt.Errorf("[debug] Failed to forward msg. Reason: %v\n", err)
	}
	return
}