Skip to content

Commit 4173f07

Browse files
ghaskinsecb
authored andcommitted
Add support for pre resolved/rejected promises
Signed-off-by: Greg Haskins <[email protected]>
1 parent 22de397 commit 4173f07

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/temporal/promise.clj

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
(:require [promesa.core :as p]
66
[temporal.internal.promise :as pt])
77
(:import [temporal.internal.promise PromiseAdapter]
8-
[io.temporal.workflow Promise]))
8+
[io.temporal.workflow Workflow Promise]))
99

1010
(defn- ->array
1111
^"[Lio.temporal.workflow.Promise;" [coll]
@@ -44,4 +44,14 @@ promises returned from [[temporal.activity/invoke]] from within workflow context
4444
```
4545
"
4646
[coll]
47-
(pt/->PromiseAdapter (Promise/anyOf (->array coll))))
47+
(pt/->PromiseAdapter (Promise/anyOf (->array coll))))
48+
49+
(defn resolved
50+
"Returns a new, fully resolved promise"
51+
[value]
52+
(Workflow/newPromise value))
53+
54+
(defn rejected
55+
"Returns a new, rejected promise"
56+
[^Exception e]
57+
(Workflow/newFailedPromise e))

test/temporal/test/sequence.clj

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
;; Copyright © 2022 Manetu, Inc. All rights reserved
2+
3+
(ns temporal.test.sequence
4+
(:require [clojure.test :refer :all]
5+
[promesa.core :as p]
6+
[taoensso.timbre :as log]
7+
[temporal.client.core :as c]
8+
[temporal.workflow :refer [defworkflow]]
9+
[temporal.activity :refer [defactivity] :as a]
10+
[temporal.test.utils :as t]
11+
[temporal.promise :as pt]))
12+
13+
(use-fixtures :once t/wrap-service)
14+
15+
(defactivity greet-activity
16+
[ctx args]
17+
(log/info "greet-activity:" args)
18+
(str "Hi, " args))
19+
20+
(defworkflow sequence-workflow
21+
[ctx _]
22+
@(-> (pt/resolved true)
23+
(p/then (fn [_]
24+
(a/invoke greet-activity "Bob")))
25+
(p/then (fn [_]
26+
(a/invoke greet-activity "Charlie")))
27+
(p/then (constantly :ok))))
28+
29+
(deftest the-test
30+
(testing "Verifies that we can process a promise-chain in sequence"
31+
(let [workflow (t/create-workflow sequence-workflow)]
32+
(c/start workflow nil)
33+
(is (= @(c/get-result workflow) :ok)))))

0 commit comments

Comments
 (0)