Created
July 2, 2017 18:09
-
-
Save wilkerlucio/c1aaa0fec4f85225435cd23e5ac5de23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns ygq.background.main | |
(:require-macros [cljs.core.async.macros :refer [go]]) | |
(:require [cljs.core.async :as async :refer [<!]] | |
[chrome.rpc :as rpc] | |
[ygq.background.parser :as p] | |
[google.api :as g])) | |
(defonce comm-listener | |
(go | |
(let [rpc (rpc/listen (async/chan 10)) | |
token (<! (g/request-token))] | |
(loop [] | |
(when-let [{::rpc/keys [payload send-response]} (<! rpc)] | |
(let [[k x] payload] | |
(case k | |
:app/graph (let [response (<! (p/parse {::g/access-token token} x))] | |
(try | |
(send-response response) | |
(catch :default _))) | |
(do | |
(js/console.info "Can't handle message" k) | |
nil))) | |
(recur)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment