// Enqueue send a message to the topic. All subscriptions receive a copy // of the message. func (t *Topic) Enqueue(f *frame.Frame) { switch t.subs.Len() { case 0: // no subscription, so do nothing case 1: // only one subscription, so can send the frame // without copying sub := t.subs.Front().Value.(Subscription) sub.SendTopicFrame(f) default: // more than one subscription, send clone for // all subscriptions except the last, which can // have the frame without copying for e := t.subs.Front(); e != nil; e = e.Next() { sub := e.Value.(Subscription) if e.Next() == nil { // the last in the list, send the frame // without copying sub.SendTopicFrame(f) } else { sub.SendTopicFrame(f.Clone()) } } } }