exa
ES7 async/await or ES6 generator route handlers for Express
Last updated 2 years ago by superpaintman .
MIT · Repository · Bugs · Original npm · Tarball
$ cnpm install exa 
SYNC missed versions from official npm registry.

exa

Linux Build Windows Build NPM version NPM Downloads Test Coverage

ES7 async/await or ES6 generator route handlers for Express

Installation

npm install exa --save

Usage

ES6 generator

const exa      = require('exa');
const express  = require('express');

const app = exa(express());

// Mem delay
function work(ms) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve();
    }, ms);
  });
}

app.$get("/", function * (req, res) {
  console.log('wow!');
  yield work(3000);
  console.log('so async!');

  res.send('ES7 soooo cool!');
});

app.$get("/error", function * (req, res) {
  throw new Error("Booom!!!");

  res.send('I will never show :(');
});

app.$post("/sync", (req, res) => {
  res.send('I\'m sync? ^__^');
});

app.$use(function * (err, req, res, next) {
  console.error(err); // "Booom" error

  console.log("Start working");
  yield work(3000);
  console.log("Finish working");

  res.statusStatus(500);
});

ES7 async/await

import exa      from 'exa'; 
import express  from 'express';

const app = exa(express());

// Mem delay
function work(ms) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve();
    }, ms);
  });
}

app.$get("/", async (req, res) => {
  console.log('wow!');
  await work(3000);
  console.log('so async!');

  res.send('ES7 soooo cool!');
});

app.$get("/error", async (req, res) => {
  throw new Error("Booom!!!");

  res.send('I will never show :(');
});

app.$post("/sync", (req, res) => {
  res.send('I\'m sync? ^__^');
});

app.$use(async (err, req, res, next) => {
  console.error(err); // "Booom" error

  console.log("Start working");
  await work(3000);
  console.log("Finish working");

  res.statusStatus(500);
});

API


Changelog


License

Copyright (c) 2016 Alexander Krivoshhekov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 11
Dependencies (3)
Dev Dependencies (18)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |