-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement an error-first callback read.
- Loading branch information
1 parent
4c83965
commit c7e6896
Showing
3 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require('proof')(1, require('cadence')(prove)) | ||
|
||
function prove (async, assert) { | ||
var Staccato = require('..') | ||
var stream = require('stream') | ||
var through = new stream.PassThrough | ||
var staccato = new Staccato(through) | ||
var gathered = [] | ||
async(function () { | ||
var loop = async(function () { | ||
staccato.read(async()) | ||
}, function (buffer) { | ||
if (buffer == null) { | ||
return [ loop.break ] | ||
} | ||
gathered.push(buffer) | ||
})() | ||
}, function () { | ||
assert(Buffer.concat(gathered).toString(), 'a', 'gathered') | ||
}) | ||
// A sub-cadence because we have to wait for the loop above to start. | ||
async(function () { | ||
setImmediate(async()) | ||
}, function () { | ||
through.write(new Buffer('a')) | ||
through.end() | ||
}) | ||
} |