       deref
       ::specs/message-loop-name
       utils/pre-log))
+
+(defn build-un-ackd-blocks
+  []
+  (sorted-set-by (fn [x y]
+                   (let [x-time (::specs/time x)
+                         y-time (::specs/time y)]
+                     (if (= x-time y-time)
+                       ;; Assume that we never have multiple messages with the
+                       ;; same timestamp.
+                       ;; We do hit this case when disj is trying to
+                       ;; remove an existing block.
+                       0
+                       (if (< x-time y-time)
+                         -1
+                         1))))))
 
 ;;;; Q: what else is in the reference implementation?
 ;;;; A: Lots. Scattered around quite a bit now

                                                      actual-next
                                                      (System/nanoTime)
                                                      success))
                                (case tag
                                  ::drained (do (log/warn prelog
                                                          ;; Actually, this seems like a strong argument for
                                                          ;; having a pair of streams. Child could still have
                                                          ;; bytes to send to the parent after the latter's
                                                          ;; stopped sending, or vice versa.
                                                          ;; I'm pretty sure the complexity I haven't finished
                                                          ;; translating stems from that case.
                                                          ;; TODO: Another piece to revisit once the basics
                                                          ;; work.
                                                          "Stream closed. Surely there's more to do"))
                                  ::timed-out (do
                                                (log/debug prelog
                                                           (cl-format nil
                                                                      "~Timer for ~:d ms after ~:d timed out. Re-triggering Output"
                                                                      delta_f
                                                                      now))
                                                (trigger-from-timer state))
                                  ::parent-> (trigger-from-parent state (second success))
                                  ::child-> (trigger-from-child state (second success)))
                                (when (not= tag ::drained)
                                        (log/debug prelog "Scheduling next timeout")
                                        ;; This is taking a ludicrous amount of time.
                                        (let [start (System/nanoTime)
                                              ;; Q: How much should I blame on logging?
                                              result (schedule-next-timeout! state-wrapper)
                                              end (System/nanoTime)]
                                          (log/debug prelog
                                                     (cl-format nil
                                                                "Scheduling next timeout took ~:d  nanoseconds"
                                                                (- end start)))
                                          result))))
                            (fn [failure]
                              (log/error failure
                                         prelog

    ;; This covers line 260
    (swap! state-atom assoc ::specs/recent recent)
    (schedule-next-timeout! (assoc state-wrapper ::stream io-stream))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Public
