-
-
Save tobias/917d0ea5680f43a66d6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(send! [ch message] [ch message options] | |
"Send a message to the channel, asynchronously. | |
`message` can either be a String or byte[]. If it is a String, it will be | |
encoded to the character set of the response for HTTP streams, and as UTF-8 | |
for WebSockets. | |
The following options are supported [default]: | |
* :close? - if `true`, the channel will be closed when the send completes. | |
Setting this to `true` on the first send to an HTTP stream channel | |
will cause it to behave like a standard HTTP response, and *not* chunk | |
the response. [false] | |
* :status - the HTTP status of the response. Used to override the status | |
returned from the handler that called `as-channel` for HTTP streams. | |
Ignored if this is not the first send to the channel. [nil] | |
* :headers - the HTTP headers of the response. Used to override the headers | |
returned from the handler that called `as-channel` for HTTP streams. | |
Ignored if this is not the first send to the channel. [nil] | |
* :on-complete - `(fn [throwable] ...)` - called when the send | |
attempt has completed. The success of the attempt is signaled by the | |
passed value, i.e. if throwable is nil. If the error requires the | |
channel to be closed, the [[as-channel]] :on-close callback will | |
also be invoked. If this callback throws an exception, it will be | |
reported to the [[as-channel]] :on-error callback [`#(when % (throw %))`] | |
Returns nil if the channel is closed when the send is initiated, true | |
otherwise. If the channel is already closed, :on-complete won't be | |
invoked.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment