Module ringo/webapp/async
This module provides support for fully asynchronous, streaming HTTP responses. Asynchronous responses can be handled by the original thread handling a HTTP request, or any other thread. Note that streaming async responses are not JSGI compatible and therefore not passed through the JSGI middleware stack.
Class AsyncResponse
AsyncResponse (request, timeout, autoflush)
Creates a streaming asynchronous response. The returned response object can be used both synchronously from the current thread or asynchronously from another thread, even after the original thread has finished execution. AsyncResponse objects are threadsafe.
Parameters
| Object | request | the JSGI request object |
| Number | timeout | the response timeout in milliseconds. Defaults to 30 seconds. |
| Boolean | autoflush | whether to flush after each write. |
AsyncResponse.prototype.close ()
Close the response stream, causing all buffered data to be written to the client.
AsyncResponse.prototype.flush ()
Flush the response stream, causing all buffered data to be written to the client.
Returns
| this response object for chaining |
AsyncResponse.prototype.start (status, headers)
Set the HTTP status code and headers of the response. This method must only be called once.
Parameters
| Number | status | the HTTP status code |
| Object | headers | the headers |
Returns
| this response object for chaining |
AsyncResponse.prototype.write (data, [encoding])
Write a chunk of data to the response stream.
Parameters
| String|Binary | data | a binary or string |
| String | [encoding] | the encoding to use |
Returns
| this response object for chaining |
