Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(ns cljsmadeeasy.core
(:require [cljs.core.async :as a])
(:require-macros [cljs.core.async.macros :refer [go]]))
(defn fill-load-chan [number-of-pages]
(let [partitions (partition-all NUM-PAGES-PER-LOAD
(range 1 (inc number-of-pages)))
c (a/chan)]
(doseq [page-numbers partitions]
(a/>! c page-numbers))
(a/close! c))
(defn load-from-chan [c]
(loop []
(when-let [page-numbers (a/<! c)]
(doseq [page-number page-numbers]
(load-page! page-number))
(a/<! (a/timeout WAIT-BETWEEN-LOAD))
(defn load-specific-page [c-mix page-number]
(let [c (a/chan)]
(a/toggle queue-mix {c {:solo true}})
(a/put! c [page-number])
(a/close! c))
(def main-chan (a/chan))
(def c-mix (a/mix main-chan))
(a/admix c-mix (fill-load-chan num-pages))
(load-from-chan main-chan))
;;load a specific page when needed
(load-specific-page c-mix page-number)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment