Skip to content

Commit

Permalink
fix: signal! resolve to nil on wrong system-name
Browse files Browse the repository at this point in the history
  • Loading branch information
armed committed Jul 4, 2022
1 parent a85f453 commit 3b363e1
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/k16/gx/beta/system.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,41 @@

(defn signal!
"Sends signal to a system and updates it in registry.
Accepts system name and a signal key.
Returns a new system on success or throws exception on signal failure."
- Accepts system name and a signal key.
- Returns a promise with a new system on success.
- Returns a resolved promise with nil if system does not exist.
- Clojure: rejects with `clojure.lang.ExceptionInfo` wrapped in
`java.util.concurrent.ExecutionException` on signal failure.
- ClojureScript: rejects with `cljs.core.ExceptionInfo` on signal failure."
([system-name signal-key]
(signal! system-name signal-key nil))
([system-name signal-key selector]
(when-let [gx-map (get @registry* system-name)]
(if-let [gx-map (get @registry* system-name)]
(-> (gx/signal gx-map signal-key selector)
(p/then (fn [g]
(swap! registry* assoc system-name g)
(if-let [failures (:failures g)]
(throw (ex-info (str "Signal failed!\n"
(gx.errors/humanize-all failures))
{:failures failures}))
g)))))))
g))))
(p/resolved nil))))

(comment
(register! :sys {:graph {:a '(gx/ref :b)
:b '(gx/ref :a)
:c '(gx/ref :z)
:z {:gx/component 'non.existend/component}}})
(try
(register! :sys {:graph {:a '(gx/ref :b)
:b '(gx/ref :a)
:c '(gx/ref :z)
:z {:gx/component 'non.existend/component}}})
(catch Exception e
(println (ex-message (or (ex-cause e) e)))))
;; clj
@(signal! :sys :gx/start)
(try
@(signal! :sys :gx/start)
(catch Exception e
(println (type e))
(println (ex-message (or (ex-cause e) e)))))

;; cljs
(-> (signal! :sys :gx/start)
Expand Down

1 comment on commit 3b363e1

@vercel
Copy link

@vercel vercel bot commented on 3b363e1 Jul 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

gx – ./

gx-kepler16.vercel.app
gx.kepler16.com
gx-git-master-kepler16.vercel.app

Please sign in to comment.