-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Channel refuses content #10
Comments
initializing the pipe with i just write to it like in the examples, how can i change this to write asynchronously? or is the Pipe not accepting blocking input a bug? |
i found a nice workaround here add to the header: const {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm")
const ThreadManager = Cc['@mozilla.org/thread-manager;1'].
getService(Ci.nsIThreadManager); add to this._asyncWait = stream.asyncWait.bind(stream) and to writeFrom: function(data, end=false) {
let self = this;
function writeNextChunk() {
self._asyncWait({
QueryInterface: XPCOMUtils.generateQI([Ci.nsIOutputStreamCallback]),
onOutputStreamReady: function() { try {
var str = data.next()
self.write(str, str.length)
writeNextChunk()
} catch (e if e instanceof StopIteration) {
if(end) self.end()
} }
}, 0, 0, ThreadManager.currentThread)
}
writeNextChunk()
} then just feed it data: function myData() {
yield 'this is so much, it’s blocking!'
}
exports.handler = protocol('much', {
onRequest: function(request, response) {
response.writeFrom(myData(), true)
}
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If i write too much/take too long, i get
The text was updated successfully, but these errors were encountered: