2 ms·
JSGI is not able to take advantage of node's ability to serve responses asynchronously because the spec doesn't allow for it. JSGI specifies that the return val
by mjijackson 15y ago
JSGI is not able to take advantage of node's ability to serve responses asynchronously because the spec doesn't allow for it. JSGI specifies that the return value of an app must be the [status, headers, body], whereas Strata specifies that the return value of an app is not important and that the app's callback should be used to serve the response instead.
This is an API incompatibility that cannot be ignored. The most developed lib I've seen up to this point to get JSGI working on node (https://github.com/kriszyp/jsgi-node https://github.com/kriszyp/jsgi-node) isn't able to get asynchronous responses working properly. Instead, it just does a body.forEach (see https://github.com/kriszyp/jsgi-node/blob/master/lib/jsgi-node.js#L167 https://github.com/kriszyp/jsgi-node/blob/master/lib/jsgi-no...) to write each piece out to the response synchronously.
Copied and pasted from https://github.com/mjijackson/strata/issues/2 https://github.com/mjijackson/strata/issues/2.
- olegp 15y agoMy JSGI implementation in Common Node (https://github.com/olegp/common-node https://github.com/olegp/common-node) uses node-fibers allowing it to stream out responses without blocking the event loop. In fact, by connecting an input stream to an output stream (forEachable objects), the underlying code automatically enables Node's pipe like behavior. Check out this example: https://github.com/olegp/common-node/blob/master/examples/http.js https://github.com/olegp/common-node/blob/master/examples/ht...
- mjijackson 15y agoEven so, this breaks down with JSGI middleware that depends on running in a Java environment. For example, JSGI's gzip middleware uses Java's byte buffers.
- olegp 15y agoWhich JSGI gzip middleware are you referring to? It should use portable CommonJS Binary objects, which in Common Node's case wraps Buffers and in RingoJS (Java) byte arrays.
- tlrobinson 15y agoJSGI is an API, not an implementation. Nothing in the API is dependent on Java.
- tlrobinson 15y agoKris Zyp's "jsgi-node" absolutely does support streaming. As does Kris Kowal's "q-http" and "jaque" framework. There have been lots of discussion on asynchronous/streaming in JSGI, but perhaps it hasn't made it's way into the specs you've looked at. Promises are one way, fibers are another. Foreach-able "streams" w/ promises and Node streams are pretty much equivalent (and yes, JSGI w/ promises can handle back pressure, though I'm not sure if there are any public implementations yet)