Created
February 25, 2010 11:47
-
-
Save oberhamsi/314479 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
include('ringo/unittest'); | |
include('ringo/scheduler'); | |
var log = require('ringo/logging').getLogger(module.id); | |
var client = require('ringo/httpclient'); | |
var Server = require('ringo/httpserver').Server; | |
var server; | |
var app = function(env) { | |
include('ringo/webapp/request'); | |
include('ringo/webapp/response'); | |
var webenv = require('ringo/webapp/env'); | |
webenv.env = env; | |
var req = webenv.req = new Request(env); | |
var res = null; | |
req.charset = config.charset || 'utf8'; | |
req.pathInfo = decodeURI(req.pathInfo); | |
var res = getResponse(req); | |
/* close() returns | |
return { | |
status: status, | |
headers: headers, | |
body: buffer | |
}; | |
*/ | |
if (res instanceof Response) { | |
return res.close(); | |
} | |
return res; | |
}; | |
var config = { | |
'host': '127.0.0.1', | |
'port': 8888, | |
}; | |
server = new Server(config); | |
server.addApplication("/", '', app); | |
server.start(); | |
/** | |
* this produces the actual request | |
*/ | |
var getResponse = function(req){ | |
// Sends a message once a second 10 times | |
var progress, finished; | |
var i = 0; | |
var intervalId = setInterval(function(){ | |
i++; | |
progress({ | |
status: 200, | |
headers:{}, | |
body: ["msg"+i] | |
}); | |
if(i == 5){ | |
clearInterval(intervalId); | |
finished({}) | |
} | |
}, 1000); | |
var promise = { | |
then: function(onFinish, onError, onProgress){ | |
finished = onFinish; | |
progress = onProgress; | |
} | |
}; | |
return promise; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment