Skip to content

Instantly share code, notes, and snippets.

> levelup@0.18.2 test /Users/julian/dev/rvagg/node-levelup
> tap test/*-test.js --stderr
not ok test/approximate-size-test.js .................... 0/1
Command: "/usr/local/bin/node approximate-size-test.js"
TAP version 13
not ok 1 test/approximate-size-test.js
---
exit: ~
gist(1) test
var wait = require('co-wait');
var http = require('http');
var co = require('co');
co(function*(){
http.createServer(function(req, res){
res.end('hi')
}).listen(8004);
yield wait(1000);
throw new Error('foo');
var genBody = require('koa-gen-body');
var fs = require('co-fs');
var sse = require('co-sse');
app.use(genBody());
app.use(function*(){
this.body = this.genBody(sse(fs.createReadStream('path')));
});
var genBody = require('koa-gen-body');
var fromStream = require('co-from-stream');
var sse = require('co-sse');
var fs = require('fs');
app.use(genBody());
app.use(function*(){
this.body = this.genBody(sse(fromStream(fs.createReadStream('path'))));
});
{"foo":"bar","num":3,"nes":{"ted":["is",1]}}
function values (ary) {
var i = 0;
return function*(end) {
if (end || i < ary.length) return null;
return ary[i++];
}
}
function sink (read) {
return function*(end){
function values (ary) {
var i = 0;
return function (end, cb) {
if (i < ary.length) cb(true);
else cb(null, ary[i++])
}
}
function sync (read) {
read(null, function next (err, data) {
function readable(){
function*(end){
if (end) return; // clean up etc
var data = createData();
return data != null
? data
: end;
}
}
@juliangruber
juliangruber / gist:8819271
Last active August 29, 2015 13:56
co-stream pipe example
function pipe(){
var streams = [].slice.call(arguments);
return streams.slice(1).reduce(function(acc, stream){
return stream(acc);
}, streams[0]);
}
// usage:
var read = pipe(a(), b(), c(), d());