Skip to content

Instantly share code, notes, and snippets.

@lightsofapollo
Created May 2, 2014 22:02
Show Gist options
  • Save lightsofapollo/22771795a2958a7062c9 to your computer and use it in GitHub Desktop.
Save lightsofapollo/22771795a2958a7062c9 to your computer and use it in GitHub Desktop.
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