<commit_before>(ns pepa.bus
  (:require [com.stuartsierra.component :as component]
            [clojure.core.async :as async :refer [>!!]]))

(defn subscribe [bus topic]
  (let [chan (async/chan (async/sliding-buffer 1))]
    (async/sub (:output bus) topic chan)
    chan))

(defn notify! [bus topic]
  (>!! (:input bus) topic ))

(defrecord Bus [input output]
  component/Lifecycle
  (start [component]
    (println ";; Starting bus")
    (let [input (async/chan)
          output (async/pub input identity)]
      (assoc component
        :input input
        :output output)))

  (stop [component]
    (println ";; Stopping bus")
    (assoc component
      :input nil
      :output nil)))

(defn make-component []
  (map->Bus {}))
<commit_msg>Some documentation notes on pepa.bus.<commit_after>(ns pepa.bus
  (:require [com.stuartsierra.component :as component]
            [clojure.core.async :as async :refer [>!!]]))

;;; pepa.bus is a simple application-wide notification bus. Clients
;;; can subscribe for any topic they want and will receive a value for
;;; any cann of `notify!' for that topic.

(defn subscribe
  "Returns a channel with that will receive a value when `notify!' is
  called for that topic."
  [bus topic]
  (let [chan (async/chan (async/sliding-buffer 1))]
    (async/sub (:output bus) topic chan)
    chan))

;;; TODO: Add optional extra data. Replace `identity' in `async/pub'
;;; below with ::topic or similar and make `notify!' put maps into the
;;; channel.
(defn notify! [bus topic]
  (>!! (:input bus) topic ))

(defrecord Bus [input output]
  component/Lifecycle
  (start [component]
    (println ";; Starting bus")
    (let [input (async/chan)
          output (async/pub input identity)]
      (assoc component
        :input input
        :output output)))

  (stop [component]
    (println ";; Stopping bus")
    (assoc component
      :input nil
      :output nil)))

(defn make-component []
  (map->Bus {}))

{'fraction_non_alphanumeric': 0.13955874807593638, 'fraction_numerical': 0.001026167265264238, 'mean_word_length': 3.1313559322033897, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5348750', 'n_tokens_mistral': 630, 'n_tokens_neox': 612, 'n_words': 208}