mirror of
https://github.com/penpot/penpot.git
synced 2025-08-07 14:38:33 +02:00
🎉 Add helper for blocking executuion on vertx.
This commit is contained in:
parent
f2eaa1b5d1
commit
e4c9d29b69
1 changed files with 28 additions and 6 deletions
28
backend/vendor/vertx/src/vertx/core.clj
vendored
28
backend/vendor/vertx/src/vertx/core.clj
vendored
|
@ -5,16 +5,17 @@
|
||||||
;; Copyright (c) 2019 Andrey Antukh <niwi@niwi.nz>
|
;; Copyright (c) 2019 Andrey Antukh <niwi@niwi.nz>
|
||||||
|
|
||||||
(ns vertx.core
|
(ns vertx.core
|
||||||
(:require [clojure.spec.alpha :as s]
|
(:require
|
||||||
|
[clojure.spec.alpha :as s]
|
||||||
[promesa.core :as p]
|
[promesa.core :as p]
|
||||||
[vertx.eventbus :as vxe]
|
[vertx.eventbus :as vxe]
|
||||||
[vertx.util :as vu])
|
[vertx.util :as vu])
|
||||||
(:import
|
(:import
|
||||||
|
io.vertx.core.AsyncResult
|
||||||
io.vertx.core.Context
|
io.vertx.core.Context
|
||||||
io.vertx.core.DeploymentOptions
|
io.vertx.core.DeploymentOptions
|
||||||
io.vertx.core.Future
|
|
||||||
io.vertx.core.Promise
|
|
||||||
io.vertx.core.Handler
|
io.vertx.core.Handler
|
||||||
|
io.vertx.core.Promise
|
||||||
io.vertx.core.Verticle
|
io.vertx.core.Verticle
|
||||||
io.vertx.core.Vertx
|
io.vertx.core.Vertx
|
||||||
io.vertx.core.VertxOptions
|
io.vertx.core.VertxOptions
|
||||||
|
@ -52,6 +53,27 @@
|
||||||
[]
|
[]
|
||||||
(Vertx/currentContext))
|
(Vertx/currentContext))
|
||||||
|
|
||||||
|
(defn wrap-blocking
|
||||||
|
([f] (wrap-blocking (current-context) f))
|
||||||
|
([ctx f]
|
||||||
|
(let [^Vertx vsm (vu/resolve-system ctx)]
|
||||||
|
(fn [& args]
|
||||||
|
(let [d (p/deferred)]
|
||||||
|
(.executeBlocking
|
||||||
|
vsm
|
||||||
|
(reify Handler
|
||||||
|
(handle [_ prm]
|
||||||
|
(try
|
||||||
|
(.resolve ^Promise prm (apply f args))
|
||||||
|
(catch Throwable e
|
||||||
|
(.fail ^Promise prm e)))))
|
||||||
|
false
|
||||||
|
(reify Handler
|
||||||
|
(handle [_ ar]
|
||||||
|
(if (.failed ^AsyncResult ar)
|
||||||
|
(p/reject! d (.cause ^AsyncResult ar))
|
||||||
|
(p/resolve! d (.result ^AsyncResult ar)))))))))))
|
||||||
|
|
||||||
(defn handle-on-context
|
(defn handle-on-context
|
||||||
"Attaches the context (current if not explicitly provided) to the
|
"Attaches the context (current if not explicitly provided) to the
|
||||||
promise execution chain."
|
promise execution chain."
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue