This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-13
Channels
- # babashka (45)
- # babashka-sci-dev (15)
- # beginners (72)
- # biff (4)
- # calva (3)
- # clj-on-windows (67)
- # clj-otel (1)
- # cljfx (7)
- # clojure (74)
- # clojure-austin (1)
- # clojure-dev (4)
- # clojure-europe (6)
- # clojure-gamedev (1)
- # clojure-germany (5)
- # clojure-losangeles (6)
- # clojure-nl (3)
- # clojure-uk (6)
- # clojured (2)
- # clojurescript (42)
- # core-typed (2)
- # cursive (4)
- # emacs (18)
- # events (1)
- # fulcro (13)
- # humbleui (8)
- # introduce-yourself (2)
- # kaocha (11)
- # leiningen (5)
- # lsp (16)
- # malli (8)
- # off-topic (69)
- # pathom (38)
- # pedestal (3)
- # reagent (17)
- # releases (3)
- # shadow-cljs (10)
- # spacemacs (6)
- # sql (1)
- # tools-deps (5)
- # xtdb (20)
Another question, maybe both can be answered whenever someone has time to catch up on these, I have a function defined for wrap effects (namely :read-file
):
(fx/wrap-effects {:context (fx/make-reset-effect *context)
:dispatch fx/dispatch-effect
:read-dir effects/recursive-directory-view
:read-file effects/read-file-content})
This works fine:
(defn read-file-content [v dispatch!]
(future
(let [c @file-cache
f (:file v)]
(if-let [cached-text (cache/lookup c f)]
(do
(compare-and-set! file-cache c (cache/hit c f)) ; prefer lose update for hit than a concurrent miss not cached
(dispatch! (assoc (:on-result v) :text cached-text)))
(let [text (lr-file/read f)]
(reset! file-cache (cache/miss c f text)) ; prefer optimistic update on miss, possibly losing another miss
(dispatch! (assoc (:on-result v) :text text)))))))
If I do it like this, preferring not to spawn a thread to read the file if it's already in hand, I get an exception on cache hit (not using future):
(defn read-file-content [v dispatch!]
(let [c @file-cache
f (:file v)]
(if-let [cached-text (cache/lookup c f)]
(do
(compare-and-set! file-cache c (cache/hit c f)) ; prefer lose update for hit than a concurrent miss not cached
(dispatch! (assoc (:on-result v) :text cached-text)))
(future
(let [text (lr-file/read f)]
(reset! file-cache (cache/miss c f text)) ; prefer optimistic update on miss, possibly losing another miss
(dispatch! (assoc (:on-result v) :text text)))))))
Exception: Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.core$promise$reify__8486 at clojure.lang.RT.seqFrom(RT.java:553) at clojure.lang.RT.seq(RT.java:533) at clojure.core$seq__5387.invokeStatic(core.clj:137) at clojure.core$seq__5387.invoke(core.clj:137) at cljfx.event_handler$wrap_effects$dispatch_sync_BANG___2133.invoke(event_handler.clj:27) at cljfx.event_handler$wrap_effects$dispatch_sync_BANG___2133.invoke(event_handler.clj:25) at log_reader.effects$read_file_content.invokeStatic(effects.clj:18) at log_reader.effects$read_file_content.invoke(effects.clj:12) at cljfx.event_handler$wrap_effects$dispatch_sync_BANG___2133.invoke(event_handler.clj:30)
Not quite sure what's going on there, but it seems your event handler - not effect function - returns a promise? And it should return effect map...
Oh, I see. You're right, one event handler is returning a derefable from a call to fx/on-fx-thread
. I meant that to be returning nil (no state changes), so maybe I need to add an explicit nil return there (EDIT: yup, that was it). Or find a way not to have to do it this way per your comment here: https://clojurians.slack.com/archives/CGHHJNENB/p1649927857568349?thread_ts=1649707330.172579&cid=CGHHJNENB
Thanks, @U47G49KHQ