koa-write
Write to koa bodies in generator style, respecting back pressure and throwing on closed sockets.
Example
var koa = ;var co = ;var write = ;var PassThrough = PassThrough;var wait = ; var app = ;app;
API
write(ctx, chunk)
Write chunk
to ctx
.
Yields as soon as you're good to write more.
Throws when the socket is already closed, so it doesn't make sense to write more.
Why not just co-write?
co-write writes to streams and
does the same http socket handling, however it expects to be passed an http
response object for that to work. In the situation where you have
stream.pipe(res)
you'll want to write to stream
, however end when
res.socket
ends.
Installation
$ npm install koa-write
License
MIT