This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| > 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: ~ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gist(1) test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'))); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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')))); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {"foo":"bar","num":3,"nes":{"ted":["is",1]}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function readable(){ | |
| function*(end){ | |
| if (end) return; // clean up etc | |
| var data = createData(); | |
| return data != null | |
| ? data | |
| : end; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()); |