Skip to content

Instantly share code, notes, and snippets.

@wilkerlucio
Created July 2, 2017 18:09
Show Gist options
  • Save wilkerlucio/c1aaa0fec4f85225435cd23e5ac5de23 to your computer and use it in GitHub Desktop.
Save wilkerlucio/c1aaa0fec4f85225435cd23e5ac5de23 to your computer and use it in GitHub Desktop.
(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