GitXplorerGitXplorer
n

ring-async

public
49 stars
7 forks
1 issues

Commits

List of commits on branch master.
Unverified
0ca6ee668bde54f4f7c329d45591e0f9bb2f94b0

expose async-body? method

nninjudd committed 10 years ago
Unverified
f767b0da143f0dc32413f9498903735fb1bf53fc

catch io exceptions when flushing buffer too

nninjudd committed 10 years ago
Unverified
4843cd3f2dca35d23d444c7ddcf1be3f6f8efda2

new release to fix stray exception printing

nninjudd committed 10 years ago
Unverified
f7f0495db2737f90db394ccb97bfda2b05d0254e

support flushing buffer to client by putting :flush on channel

nninjudd committed 10 years ago
Unverified
b33f9fe3477a994e2d4b5b15f607f79f96ef7492

close channel on IOException. switch to expecting a channel of bytes instead of strings

nninjudd committed 10 years ago
Unverified
55ac4a2a5cafb86741d1d4f45776f380045167e1

tweak punctuation

nninjudd committed 11 years ago

README

The README file for this repository.

ring-async

Ring adapter for supporting asynchronous responses.

Installation

To use ring-async, add the following to your :dependencies:

[com.ninjudd/ring-async "0.2.0"]

Usage

To return an asynchronous response that doesn't consume a thread for the duration of the request, just use ring.adapter.jetty-async/run-jetty-async instead of ring.adapter.jetty/run-jetty and return a response map where the :body is a core.async channel. Then, simply use a go block to add data to the body asynchronously.

(ns ring-async-sample
  (:require [clojure.core.async :refer [go >! chan close!]]
            [ring.adapter.jetty-async :refer [run-jetty-async]]))

(defn handler [request]
  (let [body (chan)]
    (go (loop [...]
          (if ...
            (>! body data)
            (recur ...)))
        (close! body))
    {:body body}))

(defn start []
  (run-jetty-async handler {:join? false :port 8000}))

Server-Sent Events

If you'd like to use ring-async for Server-Sent Events, you can use eventual, which provides helper libraries for both the Server in Clojure and the Client in ClojureScript.

License

Copyright © 2013 Justin Balthrop

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.