Jan Herich b889a07a86 Implement possibility for async command handlers (#1857)
* Implement possibility for async command handlers

Command handler can now return results asynchronously,
and those results as saved and persisted, indexed by
command message-id.

* Address feedback raised in PR comments

* Different handler codes + simplified error message
2017-09-18 16:08:06 +03:00

17 lines
547 B
Clojure

(ns status-im.data-store.handler-data
(:require [cljs.reader :as reader]
[status-im.data-store.realm.handler-data :as data-store]
[taoensso.timbre :as log]))
(defn get-all []
(->> (data-store/get-all-as-list)
(map (fn [{:keys [message-id data]}]
[message-id (reader/read-string data)]))
(into {})))
(defn get-data [message-id]
(-> message-id data-store/get-by-message-id :data reader/read-string))
(defn save-data [handler-data]
(data-store/save (update handler-data :data pr-str)))