Share Pastebin
Guest
Public paste!

async-jsgi

By: a guest | Feb 23rd, 2010 | Syntax: JavaScript | Size: 0.64 KB | Hits: 283 | Expires: Never
Copy text to clipboard
  1. include('ringo/scheduler');
  2.  
  3. exports.app = function myAsyncApp(request){
  4.     // Sends a message once a second 10 times
  5.     var progress, finished;
  6.     var i = 0;
  7.     var intervalId = setInterval(function(){
  8.        i++;
  9.        progress({
  10.           status: 200,
  11.           headers:{},
  12.           body: ["Every second another message"]
  13.        });
  14.        if(i == 10){
  15.           finished({})
  16.           clearInterval(intervalId);
  17.        }
  18.     }, 1000);
  19.     var promise = {
  20.         then: function(onFinish, onError, onProgress){
  21.             finished = onFinish;
  22.             progress = onProgress;
  23.         }
  24.     };
  25.     return promise;
  26. }