Created
July 21, 2013 10:48
-
-
Save almost/6048217 to your computer and use it in GitHub Desktop.
CoffeesScript generator based webserver
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
// Translated from https://github.com/maccman/mach/blob/150c06a0991674b1cb122bb9b1b0e801c52a72ac/prototypes/generators.js | |
// Uses my fork of CoffeeScript with the yield statement added at https://github.com/almost/coffee-script | |
mach = require('mach') | |
app = mach.stack() | |
Q = require('q') | |
sleep = (millis, answer) -> | |
deferredResult = Q.defer() | |
setTimeout((-> | |
deferredResult.resolve(answer) | |
), millis) | |
deferredResult.promise | |
app.use mach.commonLogger | |
app.run Q.async (request) -> | |
body = yield request.parseContent() | |
console.log('Sleeping') | |
yield sleep(200) | |
return JSON.stringify({requestBody: body}) | |
mach.serve(app, 3333) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment