This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-14
Channels
- # ai (24)
- # announcements (36)
- # babashka (15)
- # babashka-sci-dev (8)
- # beginners (18)
- # biff (4)
- # calva (24)
- # cider (13)
- # clj-kondo (1)
- # clj-on-windows (2)
- # clojars (15)
- # clojure (120)
- # clojure-dev (13)
- # clojure-europe (69)
- # clojure-nl (1)
- # clojure-norway (8)
- # clojure-uk (2)
- # clojurescript (4)
- # core-logic (2)
- # cursive (6)
- # datomic (193)
- # dev-tooling (4)
- # emacs (1)
- # hyperfiddle (57)
- # lsp (56)
- # malli (11)
- # missionary (15)
- # nbb (61)
- # off-topic (8)
- # polylith (8)
- # practicalli (2)
- # proletarian (1)
- # reitit (3)
- # releases (2)
- # remote-jobs (1)
- # shadow-cljs (13)
- # spacemacs (1)
- # specter (2)
- # sql (17)
- # tools-deps (3)
- # vim (38)
Hi! it’s possible with missionary to launch a task without blocking the thread like a future
(or just use a future
in this case) ?
missionary is agnostic to that. I.e. If you don't have any blocking calls it will not block. If you have a blocking call you should use m/via
(defn fetch-text []
(Thread/sleep 2000)
{:text "A text"})
(defn create-context []
{:page (future (fetch-text))})
(def ctx (create-context))
;; Later
@(:page ctx)
Is there a way to have a similar behaviour with missionary or it’s not the purpose of missionary and here a future is a better choice?Currently, you can emulate future semantics with dfv
:
(def fetch-text (m/sleep 2000 {:text "A text"}))
(defn create-context []
(let [v (m/dfv)]
(fetch-text v #(.printStackTrace ^Throwable %))
{:page v}))
(def ctx (create-context))
(m/? (:page ctx))
However, this is not a pattern I want to encourage, because it breaks supervision. The solution I have in mind is a new construct called memo
which memoizes a task result like future
but the underlying process starts lazily and is cancelled when it has no more subscriber, this would look like this :
(defn create-context []
{:page (m/memo fetch-text)})
More details here https://github.com/leonoel/missionary/issues/70Sorry for confusion. future
breaks supervision in the exact same way, so it is exactly as bad as dfv, which is still my current recommendation. Use this pattern https://github.com/leonoel/missionary/wiki/Task-interop#futures-promises-1