hyperfiddle

2025-08-07T03:38:06.080399Z

Hi folks, Please forgive my ignorance, but I'm noticing something surprising when reacting to a button click using a Token. You will see that I can deref a server-side future at the top level but not inside the when-some block. Is this expected behavior? What is the proper way to implement async (server-side) calls when reacting to a button press? Thank you. (ns repro (:require [hyperfiddle.electric3 :as e] [hyperfiddle.electric-dom3 :as dom]])) (e/defn Repro [] (e/client (println "Top-level Future: " (e/server @(future "hi"))) ; works (when-some [t (dom/button (dom/text "Press Me") (let [e (dom/On "click" identity nil) [t err] (e/Token e)] t))] (println "The answer is: " (e/server 5)) ; works (println "CB Future: " (e/server @(future "hi"))) ; doesn't work (t))))

xificurC 2025-08-07T07:57:47.176509Z

calling (t) spends the token and t turns nil, unmounting the when-some branch. This races with the server calls, i.e. they might cancel. A simple way to wait for a server call to finish is to sequence with case

(case (e/server @(future "hi"))
  (t))

Dustin Getz (Hyperfiddle) 2025-08-07T10:12:22.780419Z

there is an implicit do in when-some and in electric, do is concurrent, so (t) runs concurrently with the two printlns

2025-08-07T14:22:14.292199Z

Great. Thank you!