Intemporal demo with in-memory store
This demo is running intemporal with an in-memory store
Demos:Requirements
(ns intemporal.doc
(:require [intemporal.store :as s]
[intemporal.workflow :as w]
[promesa.core :as p]
(:require-macros [intemporal.macros :refer [stub-function stub-protocol defn-workflow]]
Let's define some side effects functions
(defn nested-fn [a]
[a :nested])
(defn activity-fn [a]
(let [f (stub-function nested-fn)]
(f :sub)))
(defprotocol MyActivities
(some-stuff [this a]))
(defrecord MyActivitiesImpl []
MyActivities
(some-stuff [this a] (println "record was called:" ) [a :child]))
Workflow definition
Since the js runtime does not allow blocking calls, the results of stubbed functions and protocols is a promise. The clojure version of this does not rely on promises.
(defn-workflow my-workflow [i]
(let [sf (stub-function activity-fn)
pr (stub-protocol MyActivities {})
sres (sf [1])
pres (some-stuff pr :X)]
;; use promesa to wait for promises to be realized
(p/let [v1 sres
v2 pres]
(conj [:root]
v1
v2))))
Execution
(defn init []
(let [engine (intemporal/make-workflow-engine :threads 4 :enable-logging true)
res (intemporal/start-workflow engine my-workflow [1] :workflow-id "my-wflow"
:protocols {MyActivities (->MyActivitiesImpl)})]
;; set-results!
(-> res
(bthen (fn [r]
(js/console.log "res" (clj->js r))
(set-results! (prn-str r))
(render-tables! engine "my-wflow")))
(p/catch (fn [r]
(js/console.error "error" r)
(set-results! (prn-str r)))))))
Live example
Results
;;Results go here