-
-
Save isaacs/4299905 to your computer and use it in GitHub Desktop.
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
var Writable = require('stream').Writable; | |
var util = require('util'); | |
// a lowlevel stderr writer | |
var TTY = process.binding('tty_wrap').TTY; | |
var handle = new TTY(2, false); | |
util.inherits(W, Writable); | |
function W(opts) { | |
Writable.call(this, opts); | |
} | |
W.prototype._write = function(chunk, cb) { | |
var str = util.format('chunk %j', chunk.toString()) + '\n'; | |
var req = handle.writeUtf8String(str); | |
// here's the problem. | |
// it needs to tell the Writable machinery that it's ok to write | |
// more, but that the current buffer length is handle.writeQueueSize | |
req.oncomplete = afterWrite | |
req.cb = cb; | |
console.error('before write', handle.writeQueueSize); | |
} | |
function afterWrite(status, handle, req) { | |
console.error('afterWrite', status, handle.writeQueueSize); | |
req.cb(); | |
} | |
var w = new W | |
w.write('foo'); | |
w.write('bar'); | |
w.write('baz'); | |
process.exit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment