-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
http: Reduce API surface #33118
Comments
@nodejs/web-server-frameworks |
This is a common theme in event based APIs. Should the API report only changes in state, which is sufficient to deduce current state? Or should it also be possible to see the current state, without tracking it? The pro of reducing API surface is less API surface :-). Nice. The con is every user has to track the state, so if there are multiple observers of the object, that can be a burden. The other problem is when, for example, the object is passed to a utility function at some point. The utility function will not have had the opportunity to observe the object lifetime and track its state. ChildProcess and cluster, (probably more examples) have a mixture of "current state" APIs as well as "change events". There is consistent demand for both styles. All of which is to say, I'm -0 on this, without a bit more contextt/justification, it seems unnecessarily risky, and it can be useful to poll the current state. Unless there is a technical reason tracking the state is difficult or error prone? But then again, that would be a good reason for node core to do it, and it not to be left to users (we don't want to see an |
Good points. In this specific case I would argue these properties just add confusion and there are more generic alternatives. i.e.
The example in
on-finished should not be required anymore given |
I see two solid technical reasons to reduce the API surface:
|
@ronag, you're the streams expert, but
surprised me. Anyhow, I'm not blocking, just pointing out some stuff to consider.
Its used by lots of middleware that does HTTP request logging, and its more than a little painful for npm packages that support all LTS version of node to have to decide to use it or not based on matches against So, this is a bit of an aside, but on-finished should be kept working (by changes in either Node.js or it) until its unnecessary on all supported (by us) Node.js versions, at which point we can tell packages to switch to a core API equivalent on all Node.js versions. <--- This is the general principle of how to update at a rate that doesn't break the ecosystem. |
|
I thought
Unless there is simple code using documented APIs that works equivalently on 10.x and greater I'm going to keep enouraging it to be used, in the hopes that people write code that is robust over all supported Node.js versions. I guess if someone is writing an app (not a published package), and are absolutely sure their app will never run on 10.x, they can ignore 10s existence. Is there equivalent code? |
Yes. function onFinished(res, cb) {
if (res.writableFinished) cb()
else res.on('finish', cb).on('error', cb)
} The problem with Though this is getting a little off topic... |
No, that should be for http streams as well. EDIT: Fix PR |
Maybe off topic... :-). Bringing it back:
Maybe you meant this, but I want to be very, very explicit:
I've reviewed code recently that just does I am generally in favour of changes to Node.js APIs, even backwards incompat ones, as long as they can be made gradually, and have a migration plan such that people can write code that works on all LTS node versions until the old behaviour drops off LTS, then move to the new APIs, and then we can delete the old ones. I (like most) don't understand the streams internals well enough to know if this is the case for the properties you propose to deprecate here, but if it is, I'm good. More feedback from web and http folks would be good, too. |
no
This. The problem with e.g.
No, it only works in Node 12+. I'm kind of at loss at what the argument here is? EDIT: sorry, I did not notice |
Doc deprecations are purely advisory (and mostly unnoticed), so no objections there, if there is a path towards runtime deprecation. If there is a migration plan, I'm OK with runtime deprecation. A plan of "wait until 10.x is out of support when there will be a good alternative" is fine by me. |
@ronag I'm confused why you suggest |
Isn't this closed by #36670? |
I would like to suggest that
complete
andaborted
are unnecessary API surface and should be at least doc deprecated.The user can keep of track of this state themselves by registering an
'aborted'
handler.In particular the exact semantics of e.g.
complete
is a slightly unclear and might cause more harm than use.The text was updated successfully, but these errors were encountered: