mirror of
https://github.com/penpot/penpot.git
synced 2025-01-25 07:58:49 -05: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
34
backend/vendor/vertx/src/vertx/core.clj
vendored
34
backend/vendor/vertx/src/vertx/core.clj
vendored
|
@ -5,16 +5,17 @@
|
|||
;; Copyright (c) 2019 Andrey Antukh <niwi@niwi.nz>
|
||||
|
||||
(ns vertx.core
|
||||
(:require [clojure.spec.alpha :as s]
|
||||
[promesa.core :as p]
|
||||
[vertx.eventbus :as vxe]
|
||||
[vertx.util :as vu])
|
||||
(:require
|
||||
[clojure.spec.alpha :as s]
|
||||
[promesa.core :as p]
|
||||
[vertx.eventbus :as vxe]
|
||||
[vertx.util :as vu])
|
||||
(:import
|
||||
io.vertx.core.AsyncResult
|
||||
io.vertx.core.Context
|
||||
io.vertx.core.DeploymentOptions
|
||||
io.vertx.core.Future
|
||||
io.vertx.core.Promise
|
||||
io.vertx.core.Handler
|
||||
io.vertx.core.Promise
|
||||
io.vertx.core.Verticle
|
||||
io.vertx.core.Vertx
|
||||
io.vertx.core.VertxOptions
|
||||
|
@ -52,6 +53,27 @@
|
|||
[]
|
||||
(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
|
||||
"Attaches the context (current if not explicitly provided) to the
|
||||
promise execution chain."
|
||||
|
|
Loading…
Add table
Reference in a new issue