Public Vars

Back

flush (clj)

(source)

function

(flush)
Flushes the output stream that is the current value of *out*

Examples

wilkerlucio/pathom
(ns com.wsscode.pathom.book.tracing.demo
  (:require [com.wsscode.pathom.core :as p]
            [com.wsscode.pathom.connect :as pc]
            [com.wsscode.pathom.trace :as pt]
            [clojure.core.async :as async]
            [com.wsscode.common.async-cljs :refer [go-catch <?]]))

;=>
;{:com.wsscode.pathom/trace
; {:start 0,
;  :path [],
;  :duration 5049,
;  :details [{:event "process-pending",
;             :duration 0,
;             :start 1,
;             :provides #{:com.wsscode.pathom/trace},
;             :merge-result? false}
;            {:event "flush-watchers-loop", :duration 0, :start 1}
;            {:event "reset-loop",
;             :duration 0,
;             :start 1,
;             :loop-keys [:com.wsscode.pathom/trace]}
; ...
arohner/spectrum
(ns spectrum.core-specs
  (:require [clojure.core :as core]
            [clojure.spec.alpha :as s]
            [spectrum.core :as st]
            [spectrum.types :as t]
            [spectrum.util :refer [def-instance-predicate]]))

(st/var-spec #'clojure.core/*flush-on-newline* #'boolean?)
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
  "Type annotations for the base Clojure distribution."
  #?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
  (:require [clojure.core :as cc]
            [typed.clojure :as t]
            #?(:clj [typed.ann-macros.clojure :as macros])
            #?(:clj typed.ann.clojure.jvm) ;; jvm annotations
            #?(:clj clojure.core.typed))
  #?(:clj
     (:import (clojure.lang PersistentHashSet PersistentList
                            APersistentMap #_IPersistentCollection
                            #_ITransientSet
                            IRef)
              (java.util Comparator Collection))))

cc/print [t/Any :* :-> nil]
cc/println [t/Any :* :-> nil]
cc/print-str [t/Any :* :-> t/Str]
cc/println-str [t/Any :* :-> t/Str]
#?@(:cljs [] :default [
cc/printf [t/Str t/Any :* :-> nil]
cc/format [t/Str t/Any :* :-> t/Str]
])
cc/pr [t/Any :* :-> nil]
cc/prn [t/Any :* :-> nil]
cc/flush [:-> nil]
cc/*print-length* (t/U nil false t/AnyInteger)
cc/*print-level* (t/U nil false t/AnyInteger)
#?@(:cljs [] :default [
cc/*verbose-defrecords* t/Bool
cc/print-ctor [Object [Object java.io.Writer :-> t/Any] java.io.Writer :-> nil]
])

#?@(:cljs [] :default [
clojure.main/demunge [t/Str :-> t/Str]
clojure.main/repl-prompt [:-> t/Any]
clojure.main/repl-read [t/Any t/Any :-> t/Any]
clojure.main/repl-caught [Throwable :-> t/Any]
clojure.main/repl-exception [Throwable :-> t/Any]
clojure.main/root-cause [Throwable :-> Exception]
clojure.main/repl [& :optional {:init [:-> t/Any]
                                :need-prompt [:-> t/Any]
                                :prompt [:-> t/Any]
                                :flush [:-> t/Any]
                                :read [t/Any t/Any :-> t/Any]
                                :eval [t/Any :-> t/Any]
                                :print [t/Any :-> t/Any]
                                :caught [Throwable :-> t/Any]}
                   :-> t/Any]
clojure.main/main [t/Any :* :-> t/Any]
clojure.main/load-script [t/Str :-> t/Any]
])

#?@(:cljs [] :default [
cc/*file* t/Str
])
cc/*command-line-args* (t/NilableNonEmptyASeq t/Str)
#?@(:cljs [
cc/*unchecked-if* t/Bool
cc/*unchecked-arrays* t/Bool
cc/*warn-on-infer* t/Bool
cc/enable-console-print! [:-> t/Any]
] :default [
cc/*warn-on-reflection* t/Bool
cc/*compile-path* t/Str
cc/*compile-files* t/Bool
cc/*unchecked-math* t/Bool
cc/*compiler-options* (t/Map t/Any t/Any)
cc/*in* java.io.Reader
cc/*out* java.io.Writer ;; FIXME cljs
cc/*err* java.io.Writer
cc/*repl* t/Any
])
cc/*flush-on-newline* t/Bool
cc/*print-meta* t/Bool
cc/*print-dup* t/Bool
cc/*print-readably* t/Bool
#?@(:cljs [] :default [
cc/*read-eval* (t/U ':unknown t/Bool)
])
athos/Drains
(ns drains.impl.unsafe
  (:require [clojure.core :as cc]
            [drains.protocols :as p]
            #?(:clj [drains.impl.macros :refer [def-unsafe-drains-n def-attachable-drain]]
               :cljs [drains.impl.macros :refer-macros [def-unsafe-drains-n def-attachable-drain]])
            [drains.impl.reduced :as reduced]
            [drains.impl.utils :as utils]))

(deftype UnsafeDrain [rf ^:unsynchronized-mutable val]
  p/IDrain
  (-reduced? [this] false)
  (-flush [this input]
    (let [val' (rf val input)]
      (if (cc/reduced? val')
        (reduced/->ReducedDrain (rf @val'))
        (do (set! val val')
            this))))
  (-residual [this] (rf val)))

;; defines
;;  - UnsafeDrains
;;  - UnsafeDrainsAttachable
(def-attachable-drain UnsafeDrains [^:unsynchronized-mutable ds
                                    ^:unsynchronized-mutable reduced?
                                    ^:unsynchronized-mutable active-keys]
  {:-reduced? ([this] reduced?)
   :-residual ([this]
               (reduce-kv (fn [ds k drain] (assoc ds k (p/-residual drain))) ds ds))
   :-flush ([this input]
            (reduce-kv (fn [_ k drain]
                         (let [drain' (p/-flush drain input)]
                           (when-not (identical? drain drain')
                             (update-drain! this k drain')
                             (when (p/-reduced? drain')
                               (disj-active-key! this k)
                               (when-not (seq (.-active-keys this))
                                 (update-reduced! this))))))
                       nil
                       ds))}
  DrainUpdater
  (update-drain! [this k drain]
    (set! ds (assoc ds k drain)))
  ActiveKeyUpdater
  (disj-active-key! [this k]
    (set! active-keys (disj active-keys k)))
  ReducedUpdater
  (update-reduced! [this]
    (set! reduced? true)))

(deftype UnsafeFmap [f
                     ^:unsynchronized-mutable d
                     ^:unsynchronized-mutable reduced?]
  p/IDrain
  (-reduced? [this] reduced?)
  (-flush [this input]
    (let [d' (p/-flush d input)]
      (when-not (identical? d d')
        (set! d d')
        (when (p/-reduced? d')
          (set! reduced? true))))
    this)
  (-residual [this]
    (f (p/-residual d))))

;; defines
;;  - UnsafeGroupBy
;;  - UnsafeGroupByAttachable
(def-attachable-drain UnsafeGroupBy [key-fn d ^:unsynchronized-mutable ds]
  {:-reduced? ([this] false)
   :-residual ([this] (reduce-kv #(assoc %1 %2 (p/-residual %3)) ds ds))
   :-flush ([this input]
            (let [key (key-fn input)
                  d (or (get ds key)
                        (let [d (utils/->unsafe (utils/unwrap d))]
                          (set! ds (assoc ds key d))
                          d))
                  d' (p/-flush d input)]
              (when-not (identical? d d')
                (set! ds (assoc ds key d')))))})
timothyrenner/turbine
(ns turbine.core-test
    (:require [clojure.core.async :refer [<!! >!! chan]]
              [turbine.core :refer :all]
              [clojure.test :refer :all]))

	(testing "Properly creates topology with a union route."
		(let [output-chan (chan 5) ; Landing point for the output.
			  union-in ; Make the topology, defined as it's input function.
				(first 
					(make-topology
						[[:in :in1]
						 [:scatter :in1 [[:exc1 single-!-xform]
						 				 [:exc2 double-!-xform]]]
						 [:union [:exc1 :exc2] [:ident]]
						 [:sink :ident (fn [v] (>!! output-chan v))]]))]
	  		;; Feed the input value into the topology.
			(union-in "Hello")
			;; Read off the output channel and compare. Use a set so order is 
			;; ignored.
			(let [answer (into #{} [(<!! output-chan) (<!! output-chan)])
				  truth #{"Hello!" "Hello!!"}]
				(is (= truth answer)))
			;; Close the topology to validate the route's closer logic.
			;; NOTE: This test condition is incomplete - it does not test that
			;; _all_ of the channels in the topology have closed.
			(close-topology [union-in])
			(is (= false (union-in "hello")))))
	
	(testing "Properly creates topology with a gather route."
		(let [output-chan (chan 5) ; Landing point for the output.
			  gather-in ; Make the topology, defined as it's input function.
			  	(first
					(make-topology
						[[:in :in1]
						 [:scatter :in1 [[:exc1 single-!-xform]
						 				 [:exc2 double-!-xform]]]
						 [:gather [:exc1 :exc2] [:ident]]
						 [:sink :ident (fn [v] (>!! output-chan v))]]))]
			;; Feed the input value into the topology.
			(gather-in "Hello")
			;; Read off the output channel and compare.
			(let [answer (<!! output-chan)
				  truth ["Hello!" "Hello!!"]]
				(is (= truth answer)))
			;; Close the topology to validate the route's closer logic.
			;; NOTE: This test condition is incomplete - it does not test that
			;; _all_ of the channels in the topology have closed.
			(close-topology [gather-in])
			(is (= false (gather-in "hello")))))
			
	(testing "Properly creates a topology with a collect route."
		(let [output-chan (chan 5)
			  collect-in ; Make the topology.
			  	(first
				  (make-topology
				  	[[:in :in1]
					 [:collect :in1 [:out] 
					 		   (fn [a v] (assoc a v (inc (a v 0)))) {}]
					 [:sink :out (fn [v] (>!! output-chan v))]]))]
			;; Feed a couple of input values into the topology.
			(collect-in "hi")
			(collect-in "hi")
			(collect-in "there")
			;; Close the topology to flush the collector.
			(close-topology [collect-in])
			;; Ensure the topology is closed.
			(is (= false (collect-in "hello")))
			;; Read and validate the output of the topology.
			(let [answer (<!! output-chan)
				  truth {"hi" 2 "there" 1}]
				(is (= truth answer)))))
	(testing "Properly creates a topology with no transducers."
		(let [output-chan (chan 5)
			  topology-in
			  	(first
				  	(make-topology
							[[:in :in1]
							 [:scatter :in1 [[:chan1] [:chan2] [:chan3]]]
							 [:union [:chan1 :chan2 :chan3] [:out]]
							 [:sink :out #(>!! output-chan %)]]))]
		;; Feed a value to the input topology.
		(topology-in "hello")
		(let [answer [(<!! output-chan) (<!! output-chan) (<!! output-chan)]]
			(is (= ["hello" "hello" "hello"] answer))))))