https://github.com/risto-stevcev/cljsjs-async
CLJSJS package for the async library
https://github.com/risto-stevcev/cljsjs-async
async clojurescript
Last synced: about 1 year ago
JSON representation
CLJSJS package for the async library
- Host: GitHub
- URL: https://github.com/risto-stevcev/cljsjs-async
- Owner: Risto-Stevcev
- Created: 2016-05-14T00:21:44.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-07-18T21:45:36.000Z (almost 10 years ago)
- Last Synced: 2025-02-22T08:27:01.127Z (over 1 year ago)
- Topics: async, clojurescript
- Language: JavaScript
- Homepage: https://clojars.org/cljsjs/async
- Size: 1.95 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# cljsjs/async
[](https://clojars.org/cljsjs/async)
Higher-order functions and common patterns for asynchronous code.
After adding the dependency to your project you can require the packaged library like so:
```clojure
(ns application.core
(:require cljsjs.async))
```
## Examples
#### async.parallel
```clojure
(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
```clojure
(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]
))
```