Created
May 2, 2014 22:02
-
-
Save lightsofapollo/22771795a2958a7062c9 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
var koa = require('koa'); | |
var app = koa(); | |
var Promise = require('promise'); | |
var sleep = function(n) { | |
return new Promise(function(accept) { | |
setTimeout(accept, n); | |
}); | |
}; | |
function* yetAnother() { | |
var now = Date.now(); | |
yield sleep(2000); | |
console.log('awaiting....', Date.now() - now); | |
yield sleep(100); | |
console.log('holy fucks this is nice', Date.now() - now); | |
} | |
function* otherGen (value) { | |
console.log(value); | |
yield sleep(100); | |
console.log('100ms') | |
yield sleep(2000); | |
console.log('2000ms') | |
yield yetAnother(); | |
} | |
app.use(function *() { | |
yield otherGen('is a thing'); | |
console.log('http woot'); | |
this.body = 'http woot'; | |
}); | |
app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment