Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require :reload-all Question #29

Closed
pwhittin opened this issue Sep 8, 2017 · 2 comments
Closed

Require :reload-all Question #29

pwhittin opened this issue Sep 8, 2017 · 2 comments
Labels

Comments

@pwhittin
Copy link
Collaborator

pwhittin commented Sep 8, 2017

Given the following code, I can run "lein repl", everything compiles and runs without error. If I then execute:

(require 'otplike-log.core :reload-all)

I get the following error:

CompilerException java.lang.IllegalArgumentException: No implementation of method: :exec of protocol: #'clojure.core.async.impl.protocols/Executor found for class: clojure.core.async.impl.exec.threadpool$thread_pool_executor$reify__1518, compiling:(trace.clj:15:3)

The Code

(ns otplike-log.log
  (:require [clj-time.core :as t]
            [clj-time.local :as l]
            [otplike.process :as process :refer [!]]))

(defn pad0
  [field-width n]
  (let [s (pr-str n)
        pad-count (- field-width (count s))
        pad-string (apply str (repeat pad-count "0"))]
    (str pad-string s)))

(def pad00 (partial pad0 2))

(def pad000 (partial pad0 3))

(defn get-now-str
  []
  (let [now (l/local-now)]
    (str
      (pad00 (t/year now)) "-" (pad00 (t/month now)) "-" (pad00 (t/day now))
      " "
      (pad00 (t/hour now)) ":" (pad00 (t/minute now)) ":" (pad00 (t/second now))
      "." (pad000 (t/milli now)))))

(defn get-space-delimited-values-string
  [values]
  (apply str (interpose " " values)))

(defn get-log-line
  [values]
  (str (get-now-str) ": " (get-space-delimited-values-string values) "\n"))

(process/proc-defn
  log-proc
  [log-line-fn]
  (process/receive!
    msg (do (log-line-fn msg)
          (recur log-line-fn))))

(defn create-log
  [log-fn]
  (let [log (process/spawn log-proc [(comp log-fn get-log-line)])]
    (fn
      [& values]
      (! log values))))

and here's a demo of using it:

(ns otplike-log.core
  (:require [otplike-log.log :as l])
  (:gen-class))

(defn doit
  [this-many-times moniker sleep-ms log]
  (doseq [n (range this-many-times)]
    (do
      (log moniker n)
      (Thread/sleep sleep-ms))))

(def doit-slow (partial doit 10 "slow" 1000))

(def doit-fast (partial doit 20 "fast" 500))

(defn log-to-file
  [log-file-spec]
  (fn
    [log-line]
    (spit log-file-spec log-line :append true)))

(defn example-1
  [log]
  (log
    "one"
    (+ 1 2)
    (apply str (interpose "," "three")))
  (doseq [log-message (range 10)]
    (log log-message)))

(defn example-2
  [log]
  (future (doit-fast log))
  (doit-slow log))

(defn -main
  [& args]
  (let [log (l/create-log (log-to-file "log.txt"))]
    (example-1 log)
    (example-2 log)))
@aav
Copy link
Contributor

aav commented Sep 9, 2017

it's enough to use :reload instead of :reload-all if you want to reload a single namespace.

@sskorokhodov
Copy link
Collaborator

sskorokhodov commented Sep 9, 2017

Tracing has changed significantly in otplike-0.3.x. I don't expect this problem after it is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants