<commit_before>;; Copyright © 2015, JUXT LTD.

(ns yada.resources.sse
  (:require
   [clojure.core.async :refer [chan mult tap]]
   [manifold.stream :refer [->source transform]]
   [yada.charset :as charset]
   [yada.protocols :as p]
   clojure.core.async.impl.channels
   clojure.core.async.impl.protocols
   manifold.stream.async)
  (import (clojure.core.async.impl.protocols ReadPort)))

(extend-protocol p/ResourceCoercion
  ReadPort
  (as-resource [ch]
    (let [mlt (mult ch)]
      {:produces [{:media-type "text/event-stream"
                   :charset charset/platform-charsets}]
       :methods {:get {:response (fn [ctx]
                                   (let [ch (chan)]
                                     (tap mlt ch)
                                     (transform (map (partial format "data: %s\n\n")) (->source ch))))}}})))<commit_msg>SSE resource was not returning a resource<commit_after>;; Copyright © 2015, JUXT LTD.

(ns yada.resources.sse
  (:require
   [clojure.core.async :refer [chan mult tap]]
   [manifold.stream :refer [->source transform]]
   [yada.charset :as charset]
   [yada.protocols :as p]
   [yada.resource :refer [resource]]
   clojure.core.async.impl.channels
   clojure.core.async.impl.protocols
   manifold.stream.async)
  (import (clojure.core.async.impl.protocols ReadPort)))

(extend-protocol p/ResourceCoercion
  ReadPort
  (as-resource [ch]
    (let [mlt (mult ch)]
      (resource
       {:produces [{:media-type "text/event-stream"
                    :charset charset/platform-charsets}]
        :methods {:get {:response (fn [ctx]
                                    (let [ch (chan)]
                                      (tap mlt ch)
                                      (transform (map (partial format "data: %s\n\n")) (->source ch))))}}}))))
{'fraction_non_alphanumeric': 0.14015572858731926, 'fraction_numerical': 0.004449388209121246, 'mean_word_length': 2.15061295971979, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5154333', 'n_tokens_mistral': 592, 'n_tokens_neox': 560, 'n_words': 135}