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
Calling .then() after .pipe() causes "write after end error" #1277
Comments
You can't use both. These are mutually exclusive features and can't work together. |
@pornel is there some technical reason that code like the following would be impossible? constructor() {
this.once('pipe', () => this.isPiping = true)
}
then(resolve, reject) {
if (this.isPiping) {
this.once('response', resolve)
if (reject) this.once('error', reject)
} else {
this.end(resolve, reject)
}
} |
@pornel it is indeed possible, I have made a PR complete with tests. |
@pornel in fact, if you ask me, it would be better if we could also call |
Ah, sorry, I assumed you've meant pipe for downloading the request. So this may work, although I have concerns:
|
I haven't found official documentation but it seems to? var PassThrough = require('stream').PassThrough
var a = new PassThrough()
var b = new PassThrough()
b.on('pipe', () => console.log('pipe'))
console.log('before')
a.pipe(b)
console.log('after')
All I see in the docs is
Doesn't say when the event is emitted... I don't know much about how the buffering works. Are you saying that's only a concern if we support |
I mean pipe client->server is OK, but pipe server->client is hard. |
@pornel I'm a bit confused what you mean, are you saying if we support awaiting a request that we've piped something into, you want to support awaiting a response we've piped into something as well? |
Yes. There are two kinds of pipes in superagent, and supporting end/then with only one of them creates inconsistency. Currently superagent doesn't support combination of any pipe with end/then, which may not be very useful, but at least it's a simple rule and is consistent. |
@pornel I have noticed intermittent failures with awaiting a request that I piped data into now...maybe the |
The potential for race condition is worrying, so I'm going to close this. |
I get that
.then()
is designed to send the request when not using.pipe()
.But how about making it so that after
.pipe()
is called,.then()
just waits for the request to finish instead of trying to write again?The text was updated successfully, but these errors were encountered: