This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
Welcome to nbb v1.2.174!
user=> (require '[promesa.core :as p])
nil
user=> (-> (some-async-task)
(p/timeout 200)
(p/then #(println "Task finished" %))
(p/catch #(println "Timeout" %)))
"#error {:message \"Could not resolve symbol: p/timeout\", :data {:type :sci/error, :line 2, :column 5, :message \"Could not resolve symbol: p/timeout\", :sci.impl/callstack #object[cljs.core.Volatile {:val ({:line 1, :column 1, :ns #object[Ur user], :file nil} {:line 1, :column 1, :ns #object[Ur user], :file nil, :sci.impl/f-meta {:ns #object[Ur clojure.core], :macro true, :sci/built-in true, :name ->, :arglists ([x & forms]), :doc \"Threads the expr through the forms. Inserts x as the\\n second item in the first form, making a list of it if it is not a\\n list already. If there are more forms, inserts the first form as the\\n second item in second form, etc.\"}} {:line 4, :column 5, :ns #object[Ur user], :file nil} {:line 4, :column 5, :ns #object[Ur user], :file nil, :sci.impl/f-meta {:ns #object[Ur promesa.core], :name catch, :arglists ([p f] [p pred-or-type f]), :doc \"Executes `f` when the promise `p` is rejected. Returns a promise\\n resolved with the return value of `f` function handler.\"}} {:line 3, :column 5, :ns #object[Ur user], :file nil} {:line 3, :column 5, :ns #object[Ur user], :file nil, :sci.impl/f-meta {:ns #object[Ur promesa.core], :name then, :arglists ([p f] [p f executor]), :doc \"Chains a computation `f` (function) to be executed when the promise\\n `p` is successfully resolved.\\n\\n The computation will be executed in the calling thread by default;\\n you also can provide a custom executor.\\n\\n If the function `f` returns a promise instance, it will be\\n automatically unwrapped.\"}} {:line 2, :column 5, :ns #object[Ur user], :file nil})}], :file nil, :phase \"analysis\"}, :cause #error {:message \"Could not resolve symbol: p/timeout\", :data {:type :sci/error, :line 4, :column 5, :file nil, :phase \"analysis\"}}}"
user=>
p/delay
does work but the contract is different ie it always waits the full amount of time
I think it needs to be added to sci.configs. I'll add it but for now you can use:
(js/Promise.race promise1 (p/delay 1000))
😂 2
You're my new ChatBorkPT
Welcome to nbb v1.2.174!
user=> (require '[promesa.core :as p])
nil
user=> (let [results (p/deferred)]
(p/let [answer (js/Promise.race results (p/delay 1000))]
answer))
#<Promise[~]>
user=> object is not iterable (cannot read property Symbol(Symbol.iterator))
(let [results (p/deferred)]
(p/let [answer (js/Promise.race [results (p/delay 1000)])]
answer))
incidentally ... and I think you knew it but just to nail it ... the above library API is a mix of sync / async and the use of a deferred promise is just a trick to ensure that the connection is made
(defn ->consumer
[options & {:keys [data-handler] :or {data-handler kv-data}}]
(let [consumer (KafkaConsumer. options)
connection (p/deferred)] ;; <<<------- ensure we return a connected consumer
(.on consumer "ready" (fn [] (p/resolve! connection consumer)))
(.on consumer "data" data-handler)
(.on consumer "event.error" (fn [err] (p/reject! connection err)))
(.connect consumer)
connection))
Wow that timeout trick is going to save me a lot of faffing about in future, thanks!