Liking cljdoc? Tell your friends :D

Clojars Project cljdoc badge License

Helpers for core.async

Helper pack for core.async with focus on error propagation, see docs for more and examples.

Features

  • error propagation by climbing up the go block stack via go* and <e! (all functions within this package propagate errors)
  • promise channel helpers
    • to ensure promise-chan via ->promise-chan and its behavior
    • to create promise-chan via promise-chan function with resolve and reject handlers
    • conversion from channel to promise and vice versa via c->p, p->c and <!p
  • helpers to handle callback based functions by conversion into channel via cb->c and <cb!

Getting started

Get it / add dependency

Add the following dependency to your project.clj:
Clojars Project

Usage

(ns your-project
  (:require [jtk-dvlp.async :as a]))


(defn ?do-some-async-stuff
  [& args]
  (a/go*
   (Thread/sleep 1000)
   (let [result
         {:thread-id (.getId (Thread/currentThread))
          :call-args args}]

     (println result)
     result)))

(defn ?fail-during-some-async-stuff
  [& args]
  (a/go*
   (Thread/sleep 1000)
   (->> {:thread-id (.getId (Thread/currentThread))
         :call-args args}
        (ex-info "you got a bug")
        (throw))))

(defn ?do-some-more-stuff
  []
  (a/go*
   (let [a
         (a/<e! (?do-some-async-stuff :a))

         b
         ;; Change to
         ;; (a/<e! (?do-some-async-stuff :b))
         (a/<e! (?fail-during-some-async-stuff :b))

         c
         (a/<e! (?do-some-async-stuff :c))]

     [a b c])))

(comment
  (a/go*
   (try
     (->> (?do-some-more-stuff)
          (a/<e!)
          (println "success"))
     (catch clojure.lang.ExceptionInfo e
       (println "there is an error" e)))))

Appendix

I´d be thankful to receive patches, comments and constructive criticism.

Hope the package is useful :-)

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close