 (defn build-new-segments
   [{:keys [onyx.core/results onyx.core/serialized-task onyx.core/catalog] :as event}]
   (let [downstream (keys (:egress-ids serialized-task))
-        results (map (fn [{:keys [root leaves] :as result}]
-                       (let [{:keys [id acker-id completion-id]} root] 
-                         (assoc result 
-                                :leaves 
-                                (map (fn [leaf]
-                                       (-> leaf 
-                                           (assoc :routes (add-route-data event result leaf downstream))
-                                           (assoc :id id)
-                                           (assoc :acker-id acker-id)
-                                           (assoc :completion-id completion-id)
-                                           (group-segments downstream catalog event)
-                                           (add-ack-vals)))
-                                     leaves))))
-                     results)]
+        results (doall
+                  (map (fn [{:keys [root leaves] :as result}]
+                         (let [{:keys [id acker-id completion-id]} root] 
+                           (assoc result 
+                                  :leaves 
+                                  (map (fn [leaf]
+                                         (-> leaf 
+                                             (assoc :routes (add-route-data event result leaf downstream))
+                                             (assoc :id id)
+                                             (assoc :acker-id acker-id)
+                                             (assoc :completion-id completion-id)
+                                             (group-segments downstream catalog event)
+                                             (add-ack-vals)))
+                                       leaves))))
+                       results))]
     (assoc event :onyx.core/results results)))
 
 (defn ack-routes? [routes]

  (assoc
   event
   :onyx.core/results
    (map
      (fn [segment]
        (let [segments (collect-next-segments event (:message segment))
              leaves (map leaf segments)]
          (->Result segment leaves)))
      batch)))

(defn apply-fn-bulk [{:keys [onyx.core/batch] :as event}]
  ;; Bulk functions intentionally ignore their outputs.

    (assoc
      event
      :onyx.core/results
      (doall 
        (map
          (fn [segment]
            (let [leaves (map leaf segments)]
              (->Result segment leaves)))
          batch)))))

(defn apply-fn [event]
  (if (:onyx/bulk? (:onyx.core/task-map event))
