Dont kill task worker on exceptions

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
Andrea Maria Piana 2018-10-10 10:24:35 +02:00
parent 99d33ebbc9
commit dda7c5e0f8
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
1 changed files with 11 additions and 1 deletions

View File

@ -1,6 +1,7 @@
(ns status-im.utils.async (ns status-im.utils.async
"Utility namespace containing `core.async` helper constructs" "Utility namespace containing `core.async` helper constructs"
(:require [cljs.core.async :as async] (:require [cljs.core.async :as async]
[taoensso.timbre :as log]
[status-im.utils.utils :as utils])) [status-im.utils.utils :as utils]))
(defn timeout [ms] (defn timeout [ms]
@ -8,6 +9,15 @@
(utils/set-timeout (fn [] (async/close! c)) ms) (utils/set-timeout (fn [] (async/close! c)) ms)
c)) c))
;; This wrapping is required as core.async macro replaces tries and catch with
;; https://github.com/clojure/core.async/blob/18d2f903b169c681ed008dd9545dc33458604b89/src/main/clojure/cljs/core/async/impl/ioc_helpers.cljs#L74
;; and this does not seem to play nice with desktop, and the error is bubble up killing the go-loop
(defn run-task [f]
(try
(f)
(catch :default e
(log/error "failed to run task" e))))
(defn chunked-pipe! (defn chunked-pipe!
"Connects input channel to the output channel with time-based chunking. "Connects input channel to the output channel with time-based chunking.
`flush-time` parameter decides for how long we are waiting to accumulate `flush-time` parameter decides for how long we are waiting to accumulate
@ -37,6 +47,6 @@
[& args] [& args]
(let [task-queue (apply async/chan args)] (let [task-queue (apply async/chan args)]
(async/go-loop [task-fn (async/<! task-queue)] (async/go-loop [task-fn (async/<! task-queue)]
(task-fn) (run-task task-fn)
(recur (async/<! task-queue))) (recur (async/<! task-queue)))
task-queue)) task-queue))