Skip to content

Files

Latest commit

 

History

History
 
 

async

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

cljsjs/async

[cljsjs/async "2.0.0-rc.4-0"] ;; latest release

After adding the above dependency to your project you can require the packaged library like so:

(ns application.core
  (:require cljsjs.async))

Examples

async.parallel

(def myatom (atom []))

(js/async.parallel
  (clj->js [(fn [callback]
              (js/setTimeout 
                (fn [] 
                  (swap! myatom conj "one")
                  (callback nil "one")) 200))
            (fn [callback]
              (js/setTimeout 
                (fn [] 
                  (swap! myatom conj "two")
                  (callback nil "two")) 100))])
  (fn [error response]
    (println response) ; #js [one two]
    (println @myatom)  ; [two one]
    ))

async.series

(def myatom (atom []))

(js/async.series
  (clj->js [(fn [callback]
              (js/setTimeout 
                (fn [] 
                  (swap! myatom conj "one")
                  (callback nil "one")) 200))
            (fn [callback]
              (js/setTimeout 
                (fn [] 
                  (swap! myatom conj "two")
                  (callback nil "two")) 100))])
  (fn [error response]
    (println response) ; #js [one two]
    (println @myatom)  ; [one two]
    ))