throwback

WebJar for throwback

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

throwback
Last Version

Last Version

4.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

throwback
WebJar for throwback
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/serviejs/throwback

Download throwback

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/throwback/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>throwback</artifactId>
    <version>4.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/throwback/
implementation 'org.webjars.npm:throwback:4.1.0'
// https://jarcasting.com/artifacts/org.webjars.npm/throwback/
implementation ("org.webjars.npm:throwback:4.1.0")
'org.webjars.npm:throwback:jar:4.1.0'
<dependency org="org.webjars.npm" name="throwback" rev="4.1.0">
  <artifact name="throwback" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='throwback', version='4.1.0')
)
libraryDependencies += "org.webjars.npm" % "throwback" % "4.1.0"
[org.webjars.npm/throwback "4.1.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

Throwback

NPM version NPM downloads Build status Test coverage

Simple asynchronous middleware pattern.

Installation

npm install throwback --save

Usage

Compose asynchronous (promise-returning) functions.

const { compose } = require("throwback");

const fn = compose([
  async function(ctx, next) {
    console.log(1);

    try {
      await next();
    } catch (err) {
      console.log("throwback", err);
    }

    console.log(4);
  },
  async function(ctx, next) {
    console.log(2);

    return next();
  }
]);

// Callback runs at the end of the stack, before
// the middleware bubbles back to the beginning.
fn({}, function(ctx) {
  console.log(3);

  ctx.status = 404;
});

Tip: In development (NODE_ENV !== "production"), compose will throw errors when you do something unexpected. In production, the faster non-error code paths are used.

Example

Build a micro HTTP server!

const { createServer } = require("http");
const finalhandler = require("finalhandler"); // Example only, not compatible with single `ctx` arg.
const { compose } = require("throwback");

const app = compose([
  function({ req, res }, next) {
    res.end("Hello world!");
  }
]);

createServer(function(req, res) {
  return app({ req, res }, finalhandler());
}).listen(3000);

Use Cases

Inspiration

Built for servie and inspired by koa-compose.

License

MIT

org.webjars.npm

ServieJS

Versions

Version
4.1.0
1.1.0