Skip to content

Instantly share code, notes, and snippets.

@tristanstraub
Created December 29, 2016 20:51
Show Gist options
  • Save tristanstraub/1fdac52a725cdd61cdc43c79a5e91c3c to your computer and use it in GitHub Desktop.
Save tristanstraub/1fdac52a725cdd61cdc43c79a5e91c3c to your computer and use it in GitHub Desktop.
Javascript async interop between callbacks/promises and channels
(ns service.async
(:require-macros [cljs.core.async.macros :as a])
(:require [cljs.core.async :as a]))
(defn <cb [f & args]
(let [out (a/chan)]
(apply f (conj (into [] args) #(a/close! out)))
out))
(defn <promise [f & args]
(let [out (a/chan)
done (fn [& _] (a/close! out))]
(.then (apply f args) done done)
out))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment