Socket
Book a DemoInstallSign in
Socket

koa-gen-body

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-gen-body

Generator stream bodies

latest
npmnpm
Version
0.0.0
Version published
Maintainers
1
Created
Source

koa-gen-body

Experimenting with generator stream bodies for koa.

Until https://github.com/joyent/node/issues/7043 is resolved this has to be coupled to koa for otherwise there will be no end event.

For more rationale see https://github.com/koajs/koa/issues/207 and https://github.com/koajs/koa/pull/208.

Example

var koa = require('koa');
var genBody = require('koa-gen-body');
var wait = require('co-wait');

var app = koa();
app.use(genBody());
app.use(function*(){
  this.body = this.genBody(function*(end){
    if (end) return console.log('end');
    yield wait(1000);
    return Date.now() + '\n';
  });
});
app.listen(3000);

API

genBody()

ctx#genBody(fn)

Create a readable stream that pull data from generator function fn.

fn will be passed the end argument, which if true tells you to end what you're doing - useful for cleaning up underlying resources.

Installation

$ npm install koa-gen-body

License

MIT

FAQs

Package last updated on 04 Feb 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts