Skip to content

Instantly share code, notes, and snippets.

@kumavis
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumavis/220699f0fc5d52e2cfc4 to your computer and use it in GitHub Desktop.
Save kumavis/220699f0fc5d52e2cfc4 to your computer and use it in GitHub Desktop.
Example of es6 transpile
var koa = require('koa');
var app = koa();
// logger
app.use(function *(next){
var start = new Date;
yield next;
var ms = new Date - start;
console.log('%s %s - %s', this.method, this.url, ms);
});
// response
app.use(function *(){
this.body = 'Hello World';
});
app.listen(3000);
@kumavis
Copy link
Author

kumavis commented Jan 21, 2015

"use strict";

var koa = require("koa");
var app = koa();

// logger

app.use(regeneratorRuntime.mark(function callee$0$0(next) {
  var start, ms;
  return regeneratorRuntime.wrap(function callee$0$0$(context$1$0) {
    while (1) switch (context$1$0.prev = context$1$0.next) {
      case 0:
        start = new Date();
        context$1$0.next = 3;
        return next;
      case 3:
        ms = new Date() - start;
        console.log("%s %s - %s", this.method, this.url, ms);
      case 5:
      case "end":
        return context$1$0.stop();
    }
  }, callee$0$0, this);
}));

// response

app.use(regeneratorRuntime.mark(function callee$0$1() {
  return regeneratorRuntime.wrap(function callee$0$1$(context$1$0) {
    while (1) switch (context$1$0.prev = context$1$0.next) {
      case 0:
        this.body = "Hello World";
      case 1:
      case "end":
        return context$1$0.stop();
    }
  }, callee$0$1, this);
}));

app.listen(3000);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment