code: func (e ActualLRPEventCalculator) EmitEvents(beforeSet, afterSet []*models.ActualLRP) {
  	events := []models.Event{}
  
  	beforeGroup := models.ResolveActualLRPGroup(beforeSet)
  	afterGroup := models.ResolveActualLRPGroup(removeNilLRPs(afterSet))
  
  	for _, ev := range generateLRPGroupEvents(beforeGroup, afterGroup) {
  		e.ActualLRPGroupHub.Emit(ev)
  	}
  
  	// stretch the two slices to be of equal size.  make sure we do this after
  	// emitting the group events, otherwise ResolveActualLRPGroup will panic if
  	// it encounters nil lrps.
  	stretchSlice(&beforeSet, &afterSet)
  
  	for i := range afterSet {
  		events = append(events, generateLRPInstanceEvents(beforeSet[i], afterSet[i])...)
  	}
  
  	sort.Slice(events, func(i, j int) bool {
  		return EventScore(events[i]) > EventScore(events[j])
  	})
  
  	for _, ev := range events {
  		e.ActualLRPInstanceHub.Emit(ev)
  	}
  }
docs: // EmitEvents emits the events such as when the changes identified in the
  // events are applied to the beforeSet the resulting state is equal to
  // afterSet.  The beforeSet and afterSet are assumed to have the same process
  // guid and index.