Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
CoffeesScript generator based webserver
// 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