Skip to content

Instantly share code, notes, and snippets.

@bjouhier
Created May 27, 2011 21:37
Show Gist options
  • Save bjouhier/996238 to your computer and use it in GitHub Desktop.
Save bjouhier/996238 to your computer and use it in GitHub Desktop.
Compiled version of requestBug_.js
/*** Generated by streamline 0.1.22 - DO NOT EDIT ***/
var __global = typeof global !== 'undefined' ? global : window;
function __cb(_, fn) { var ctx = __global.__context; return function(err, result) { __global.__context = ctx; if (err) return _(err); try { return fn(null, result); } catch (ex) { return __propagate(_, ex); } } }
function __future(fn, args, i) { var done, err, result; var cb = function(e, r) { done = true; err = e, result = r; }; args = Array.prototype.slice.call(args); args[i] = function(e, r) { cb(e, r); }; fn.apply(this, args); return function(_) { if (done) _.call(this, err, result); else cb = _.bind(this); }.bind(this); }
function __propagate(_, err) { try { _(err); } catch (ex) { __trap(ex); } }
function __trap(err) { if (err) { if (__global.__context && __global.__context.errorHandler) __global.__context.errorHandler(err); else console.error("UNCAUGHT EXCEPTION: " + err.message + "\n" + err.stack); } }
(function(_) {
var __then = (_ = (_ || __trap));
/* 1 */ var streams = require("streamline/lib/streams/streams");
/* 2 */ var flows = require("streamline/lib/util/flows");
/* 3 */ var port = 3001;
/* 5 */ var values = [1,2,3,4,5,];
/* 7 */ function send(_, path, val) {
if (!_) {
return __future(send, arguments, 0);
}
;
var __then = _;
/* 11 */ return streams.httpRequest({
/* 9 */ method: "put",
/* 10 */ url: (("http://localhost:" + port) + path)
/* 11 */ }).write(__cb(_, function(__0, __1) {
/* 11 */ return __1.end().response(__cb(_, function(__0, __2) {
/* 11 */ return __2.readAll(_);
}));
/* 11 */ }), ("" + val));
};
/* 14 */ function reply(response, statusCode, str) {
/* 15 */ response.writeHead(statusCode, {
/* 16 */ "content-type": "text/plain"
/* 17 */ }).end(str);
};
/* 42 */ return new streams.HttpServer(function __1(request, response, _) {
if (!_) {
return __future(__1, arguments, 2);
}
;
var __then = _;
var result;
/* 21 */ return request.readAll(__cb(_, function(__0, body) {
var __break = __then;
/* 22 */ switch (request.url) {
/* 23 */ case "/foo":
var futures = values.map(function __1(i) {
/* 24 */ return send(null, "/bar", i);
/* 25 */ });
return flows.collect(__cb(_, function(__0, __3) {
/* 27 */ result = __3.join(",");
/* 27 */ reply(response, 200, result);
/* 28 */ return __break();
}), futures);
/* 27 */ case "/bar":
return send(__cb(_, function(__0, __4) {
/* 30 */ result = __4;
reply(response, 200, result);
/* 31 */ return __break();
}), "/zoo", (2 * parseInt(body)));
/* 32 */ case "/zoo":
reply(response, 200, ("#" + body));
/* 31 */ return __break();
default:
/* 34 */ reply(response, 404, ("not found: " + request.url));
/* 34 */ return __break();
/* 35 */ };
}));
}).listen(__cb(_, function() {
console.log((("server ready. try http://localhost:" + port) + "/foo"));
/* 37 */ return __then();
/* 38 */ }), port);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment