Skip to content
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

feat(std/node/stream): Add node Readable Stream / Writable Stream / errors support #7569

Merged
merged 6 commits into from Nov 21, 2020

Conversation

Soremwar
Copy link
Contributor

@Soremwar Soremwar commented Sep 18, 2020

  • Add as many tests as possible before refactors
  • Add types
  • Writable and Readable both have references to children classes (Transform, Duplex, etc) god knows why. Refactor where possible and move code to correspoding child implementations
  • Convert errors to class type

@ebebbington
Copy link
Contributor

does this pr need those .js files or are they more for referencing while this PR is in progress?

@Soremwar
Copy link
Contributor Author

@ebebbington WIP, should be TS for when we end this

@Soremwar Soremwar marked this pull request as draft September 18, 2020 22:59
@CLAassistant
Copy link

CLAassistant commented Sep 18, 2020

CLA assistant check
All committers have signed the CLA.

@ebebbington
Copy link
Contributor

@Soremwar and i are working on this but are happy for other people to lend a hand!

@Soremwar
Copy link
Contributor Author

@ebebbington Looks like we have readable streams!!

@Soremwar
Copy link
Contributor Author

import { Readable } from '../deno/std/node/stream.js';

const rs = new Readable();

rs.on("data", (chunk) => {
  console.log(chunk.toString());
});

rs.on("end", () => {
  console.log("finished")
});

rs.push('and begin');
rs.push('follow along');
rs.push(null);

@Soremwar
Copy link
Contributor Author

.pause and .resume seem to be working fine!

@Soremwar
Copy link
Contributor Author

Writable streams are gonna be a b*tch. Duplex needs to inherit from both, but since JavaScript only has single prototypal inheritance it couldn't be done in an easy way. All instance checks for Duplex are for some reason inside Writable, so I'm having a hard time guessing what to yeet and what not.

@ebebbington
Copy link
Contributor

Nice one @Soremwar !!!!!!! I think i know of an example that uses duplex if that might help?

@Soremwar
Copy link
Contributor Author

Soremwar commented Sep 19, 2020

@ebebbington Duplex will wait for now

I think I got working Writable streams, but we need tests to make sure everything is OK so Duplex can inherit from both safely

import Writable from '../deno/std/node/_stream/writable.js';

const myStream = new Writable();

myStream._write = (chunk, encoding, done) => {
  console.log({
    data: chunk.toString(),
    encoding,
  })
  done();
}

myStream.write("conquer");
myStream.write("and");
myStream.write("devour");
myStream.end();

@ebebbington
Copy link
Contributor

just to check which modules will the pr implement?

  • http
  • streams
  • any others?

@ebebbington
Copy link
Contributor

ill try work on getting the http tests setup, or at least placeholders as nothing really works atm lol

@Soremwar
Copy link
Contributor Author

Https too if we manage to make http extensible

@Soremwar
Copy link
Contributor Author

Anyways if this grows too big we might just land streams for now

@ebebbington
Copy link
Contributor

Yeah definitely will end up making it extensible, just a matter of finding what methods both would share

@Soremwar
Copy link
Contributor Author

Green on readable streams !!

@Soremwar Soremwar force-pushed the streams branch 2 times, most recently from 1dddd0c to 1a6d941 Compare September 20, 2020 20:02
@Soremwar
Copy link
Contributor Author

@ebebbington I think I got Duplex working :) But I'm needing some of the examples you said you had earlier to actually test them

@ebebbington
Copy link
Contributor

ebebbington commented Sep 20, 2020

@Soremwar It might not be specifically related so it might not actually help, but i just remember seeing something around duplex's: https://github.com/linux-china/rsocket-deno/blob/master/rsocket/DuplexConnection.ts

Good job tho!:)

@Soremwar
Copy link
Contributor Author

Soremwar commented Sep 22, 2020

After many hours of work I've decided to split this PR into pieces so it can be easier to review(over 17000 lines as of now) and convert to TypeScript.

This PR will only address Readable, and Writable streams.
Http progress, duplex, transform, pipeline, promises and others will be moved to other branch were progress will be continued.

For now none of the interfaces will be exposed directly, but through the _streams folder.

@Soremwar Soremwar changed the title Add node stream/http/https support Add node Readable Stream / Writable Stream support Sep 22, 2020
@Soremwar Soremwar changed the title Add node Readable Stream / Writable Stream support Add node Readable Stream / Writable Stream / errors support Sep 22, 2020
@Soremwar Soremwar force-pushed the streams branch 2 times, most recently from e04f36e to bbd5154 Compare September 27, 2020 21:36
@Soremwar
Copy link
Contributor Author

This is finally ready to go!!

There are a couple improvements that could be done, but this should be ready for review

@Soremwar Soremwar marked this pull request as ready for review September 27, 2020 21:42
@Soremwar Soremwar force-pushed the streams branch 2 times, most recently from 1d90386 to b850cbf Compare September 27, 2020 23:11
std/node/_stream/buffer_list.ts Outdated Show resolved Hide resolved
Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an unintended change in std/wasi - please undo

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Soremwar Thanks for this work. It's obviously a very large patch, so it's difficult to review in detail - but I'm happy to land this once my minor comments are resolved.

@Soremwar Soremwar force-pushed the streams branch 2 times, most recently from 8239bf5 to 8b4f779 Compare November 21, 2020 18:21
@Soremwar
Copy link
Contributor Author

Comments resolved

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thank you @Soremwar !

@ry ry merged commit a4f27c4 into denoland:master Nov 21, 2020
@Soremwar Soremwar deleted the streams branch November 21, 2020 21:31
@benjamingr
Copy link
Contributor

Well pretty sure merging an incompatible implementation of Readable/Writeable with subtle timing differences was a mistake 😅

#7569 (comment)

It'll be good for a "10 things I regret about" talk in a few years though.

@guybedford
Copy link
Contributor

@benjamingr there's nothing binding about any of the code here - there is a stable support target which is Node.js support, and breaks to achieve that are fine under the experimental status. Perhaps we unify on a separate package outside of Deno at a later point as a collaborative effort, and I'd be all for that. There are some hard problems there around code linking though that may be clearer in due course. Matteo mentions readable-stream needs work - therefore the more people gaining first-principles experience with this code and problem space, the better, to eventually work towards the best maintainable polyfill approach.

@benjamingr
Copy link
Contributor

benjamingr commented Nov 23, 2020

Look Guy - here is my perspective:

I feel like if Steven was just given another week or two to work on the portable readable-stream bit we wouldn't get a version with lots of subtle timing bugs.

Why would Deno prefer to have a non-working version of Readable/Writeable and not a working one given ongoing work on is happening by Steven in nodejs/readable-stream.

@guybedford
Copy link
Contributor

@benjamingr great to see there is work at nodejs/readable-stream#452, I wasn't aware of this. I'm also only tangentially involved - I approved this PR before I was aware of those bugs and your comments. The path above you outlined sounds like a good plan to me, my comment was to say that there's nothing stopping that from still happening. I'm all for ripping this stuff out and better structuring it.

This PR has been open for two months, and merging it allows continuing to progress on stdlib work that relies on streams such as http / https. Otherwise everyone is blocked on Steven's hypothetical two week work, as am I with my own experiments here.

Ideally we'd certainly have a sort of build that does a code deploy from a well-maintained shared library into this deno stdlib though... and steps to work towards that would be beneficial. I was under the impression this PR was close to a manual first attempt at that and that the plan was to have follow-ups to better structure the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants