From 24d0b68c1f6c40cca99e030a3937786ee5aca98e Mon Sep 17 00:00:00 2001 From: janherich Date: Thu, 11 Jan 2018 15:55:55 +0100 Subject: [PATCH] Async audit --- src/status_im/chat/handlers.cljs | 6 +- src/status_im/native_module/impl/module.cljs | 3 +- src/status_im/protocol/web3/delivery.cljs | 60 +++++++++++--------- src/status_im/utils/event.cljs | 9 --- src/status_im/utils/pre_receiver.cljs | 11 ++-- src/status_im/utils/scheduler.cljs | 10 ---- 6 files changed, 40 insertions(+), 59 deletions(-) delete mode 100644 src/status_im/utils/event.cljs delete mode 100644 src/status_im/utils/scheduler.cljs diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 66af0acf7c..7ea23394ae 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -1,7 +1,5 @@ -(ns status-im.chat.handlers - (:require-macros [cljs.core.async.macros :as am]) - (:require [re-frame.core :refer [enrich after debug dispatch reg-fx]] - [cljs.core.async :as a] +(ns status-im.chat.handlers + (:require [re-frame.core :refer [enrich after debug dispatch reg-fx]] [clojure.string :as string] [status-im.ui.components.styles :refer [default-chat-color]] [status-im.chat.constants :as chat-consts] diff --git a/src/status_im/native_module/impl/module.cljs b/src/status_im/native_module/impl/module.cljs index 6e645190ef..58fe3b5cd6 100644 --- a/src/status_im/native_module/impl/module.cljs +++ b/src/status_im/native_module/impl/module.cljs @@ -6,8 +6,7 @@ [taoensso.timbre :as log] [cljs.core.async :as async :refer [pending-message (atom {})) -(defn set-pending-mesage-callback! - [callback] - (reset! pending-message-callback callback)) +(def ^:private pending-message-queue (async/chan 100)) -(defn add-pending-message! - [web3 {:keys [type message-id requires-ack? to ack?] :as message}] - {:pre [(valid? :protocol/message message)]} - (go - (debug :add-pending-message! message) - ;; encryption can take some time, better to run asynchronously +(async/go-loop [[web3 {:keys [type message-id requires-ack? to ack?] :as message}] + (async/pending-message - update to set/union #{[web3 message-id to]})))))))) + update to set/union #{[web3 message-id to]})))))) + (recur (async/pending-message to)] diff --git a/src/status_im/utils/event.cljs b/src/status_im/utils/event.cljs deleted file mode 100644 index 25e1775b99..0000000000 --- a/src/status_im/utils/event.cljs +++ /dev/null @@ -1,9 +0,0 @@ -(ns status-im.utils.event - (:require [cljs.core.async :refer [> seen (filter (fn [[_ x]] (= x id))) @@ -30,7 +26,8 @@ (async/go-loop [] (let [{:keys [id clock-value] :as msg} (async/ms [s] (* 1000 s)) - -(defn execute-later - [function timeout-ms] - (go (