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
;; create a store
(def mstore (s/make-memstore))
;; start some worker that knows how to resolve protocol implementations
(def worker (w/start-worker! mstore {`MyActivities (->MyActivitiesImpl)}))
;; finally, call your workflow
(let [res (w/with-env {:store mstore}
(my-workflow 1))]
Live example
Results
;;Results go here