UNPKG

stick

Version:

JSGI based webapp framework

123 lines (122 loc) 7.12 kB
<!DOCTYPE html > <html lang="de" dir="ltr"> <head> <title>stick/middleware/continuation - Stick API</title> <link rel="shortcut icon" href="http://ringojs.org/favicon.ico" type="image/x-icon" /> <link rel="icon" href="http://ringojs.org/favicon.ico" type="image/x-icon" /> <link rel="stylesheet" href="../../../static/style.css" /> <link rel="stylesheet" href="../../../static/jsdoc.css" /> <script type="text/javascript" src="../../../static/jquery.js"></script> <script type="text/javascript" src="../../../static/jsdoc.js"></script> <script> $(document).ready(jsdocSetup); </script> </head> <body> <div class="wrap"> <div class="main"> <div class="content"> <h1 class="modulename">Module stick/middleware/continuation</h1> <div class="fileoverview"> <p>Provide support for JavaScript 1.7 generator actions. </p> <p>This middleware supports two types of yield values from generators: Promises and JSGI response objects.</p> <p>If a generator action yields a promise, this middleware adds a listener to that promise that will feed the value back to the generator once the promise is resolved. If the promise resolves to an error, the error is thrown in the generator.</p> <p>For example, if <code>promise</code> is a promise, the <code>yield</code> statement will interrupt execution of the action until the promise is resolved, at which point the generator is resumed with the value of the promise being assigned to the <code>resolved</code> variable.</p> <pre><code>var resolved = yield promise;</code></pre> <p>If a generator action yields a JSGI response, the response is sent to the client. To be able to yield more than one response from the same generator, the generator has to be associated with a continuation id and stored in the user's session. This is done by calling <code>continuation.activate()</code> before yielding the first response. The <code>activate()</code> method tells the middleware to store the generator in the user's session and returns a contination id.</p> <p>For subsequent invocations of the generator, the continuation id has to be set as query string parameter with name <code>_c</code>. When suspended generator is resumed, the new request object is passed in as value for the last yield statement.</p> <pre><code>function continuation(request) { var c = app.continuation.activate(); while(true) { request = yield response.html(linkTo(app, {_c: c})); } }</code></pre> <p>See <a href="http://blog.ometer.com/2010/11/28/a-sequential-actor-like-api-for-server-side-javascript/">http://blog.ometer.com/2010/11/28/a-sequential-actor-like-api-for-server-side-javascript/</a> for background.</p> </div> <div class="classoverview"> <div> <h3>Functions</h3> <ul class="propertyoverview"> <li> <a href="#middleware" class="jsdoc-title"> middleware</a>(next, app) </li> </ul> </div> <div class="classes"> </div> </div> <hr/> <div class="details"> <!-- tpl-docitem --> <div> <div class="docitem" docitem="middleware"> <h3> <span class="itemtitle"><a id="middleware" href="#middleware" class="itemtitle itemname">middleware</a></span> <span class="itemtitle light">(next, app)</span></h3> <div> </div> <div> <h4>Parameters</h4> <table> <tr> <td></td> <td class="paramname">next</td> <td></td> </tr> <tr> <td></td> <td class="paramname">app</td> <td></td> </tr> </table> </div> </div> <hr/> </div> </div> </div> </div> <div class="menu" style="margin-top: 1em; font-size: 13px;"> <p> <a class="repositoryname" href="../../../index.html">Stick API </a> </p> Filter:<br /> <input id="jsdoc-leftnavsearch" type="search" size="14"> <ul class="jsdoc-leftnav leftnav"> <li><a href="../../../stick/index.html"> stick </a></li> <li><a href="../../../stick/helpers/index.html"> stick/helpers </a></li> <li><a href="../../../stick/middleware/index.html"> stick/middleware </a></li> <li><a href="../../../stick/middleware/basicauth/index.html"> stick/middleware/basicauth </a></li> <li><a href="../../../stick/middleware/continuation/index.html"> stick/middleware/continuation </a></li> <li><a href="../../../stick/middleware/error/index.html"> stick/middleware/error </a></li> <li><a href="../../../stick/middleware/etag/index.html"> stick/middleware/etag </a></li> <li><a href="../../../stick/middleware/gzip/index.html"> stick/middleware/gzip </a></li> <li><a href="../../../stick/middleware/method/index.html"> stick/middleware/method </a></li> <li><a href="../../../stick/middleware/mount/index.html"> stick/middleware/mount </a></li> <li><a href="../../../stick/middleware/notfound/index.html"> stick/middleware/notfound </a></li> <li><a href="../../../stick/middleware/params/index.html"> stick/middleware/params </a></li> <li><a href="../../../stick/middleware/profiler/index.html"> stick/middleware/profiler </a></li> <li><a href="../../../stick/middleware/render/index.html"> stick/middleware/render </a></li> <li><a href="../../../stick/middleware/requestlog/index.html"> stick/middleware/requestlog </a></li> <li><a href="../../../stick/middleware/route/index.html"> stick/middleware/route </a></li> <li><a href="../../../stick/middleware/session/index.html"> stick/middleware/session </a></li> <li><a href="../../../stick/middleware/static/index.html"> stick/middleware/static </a></li> <li><a href="../../../stick/middleware/upload/index.html"> stick/middleware/upload </a></li> </ul> </div> </div> </body> </html>