-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
io: change Reader interface #2591
Conversation
@kt3k you need to update |
@kt3k Cool! This is going to make v0.11 bump in std painful. We should start a PR over there before the release. |
@bartlomieju Thank you! 👍 @ry OK. I'll start it soon! |
ah, http_benchmark seems depending on std/http, std/io, etc.
Now I'm working on deno_std side kt3k/deno_std@fcda701 |
@kt3k you should be able to update the submodule in js/deps/https/deno.land/std to your branch to be able to test. |
👍🏻👍🏻👍🏻 |
4bcec78
to
5b3ed57
Compare
@kt3k This looks good to me. Is this branch ready to land? It's a bit of a tricky situation with the deno_std upgrades... |
@ry I think that If we have something like beta release of deno (which only developers can access) and beta branch of deno_std, we can do more graceful updates in this kind of situation. |
@kt3k latest Deno release will work with latest release of standard lib. I think it's fine if there's a minor break on master branches.
-1 for now, since we're still not past 1.0 seems like a waste of resources |
@ry
I agree with this. Maybe it's better to have such workflow after 1.0. |
tools/deno_http_proxy.ts
Outdated
// TODO(kt3k): lib.deno_runtime.d.ts has 2 EOF types: Deno.EOF and io.EOF. | ||
// They are identical symbols, and should be compatible. However typescript | ||
// recognizes they are different types and the below call doesn't compile. | ||
// @ts-ignore | ||
req.respond(resp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's annoying.
@kitsonk can you advise us?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kitsonk
I have trouble with this line. The error is like the below:
lib.deno_runtime.d.ts of this branch contains two EOF unique symbol
declarations. (This seems strange because in this branch EOF is defined only once, but .d.ts treat it as different types depending on where it is used.)
I tried to move EOF to several other places (js/eof.ts, js/deno.ts, etc) to avoid this, but I couldn't find a solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably doing something in deno_std like
export const EOF: unique symbol = Deno.EOF || Symbol("EOF");
export type EOF = typeof EOF;
?
(I did not follow the context of this discussion so I might be wrong)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem seems more subtle to me.
This change doesn't include 2 symbol definitions. EOF is defined only in io.ts
. deno.ts
import it and re-export it. In that case, EOF in io.ts and EOF in deno.ts should be the same thing. But lib.deno_runtime.d.ts (= deno types
) includes 2 EOFs under namespace Deno
and namespace io
. Actually lib.deno_runtime.d.ts includes the entire contents of io.ts
twice in Deno and io namespaces. (io namespace is not accessible from the user (maybe). I'm not sure why this exists. Probably a workaround for something.)
lib.deno_runtime.d.ts is created by the special tool //tools/ts_library_builder/
. I suspect something goes wrong in it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found a workaround for this:
in //js/io.ts
// TODO: Make this symbol type
export const EOF: "EOF" = "EOF";
export type EOF = typeof EOF;
This avoids the above problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@j-f1
I think symbol type is ideal for the type of EOF and we need to make it symbol in the future. But for now I don't see any way to declare it as symbol correctly, so I would suggest the above as an alternative path to make things forward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found another workaround. If we move EOF
to global namespace (window), it seemed working. The diff looks like this ( kt3k@828cf3a )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kt3k TBH I don't understand the issue, but I'm fine with that workaround (it's better than making it global). I think we should just move forward with this change and try to clean it up in later. I suspect some changes to ts_library_builder could fix this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you do export const EOF: typeof Deno.EOF = Deno.EOF
in io.ts
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ry OK. I'll update the PR to use the workaround.
I suspect some changes to ts_library_builder could fix this.
I agree that this needs some changes to ts_library_builder.
@j-f1
That causes the following error:
python ../../tools/run_node.py ../../node_modules/ts-node/dist/bin.js --project /Users/kt3k/s/deno/tools/ts_library_builder/tsconfig.json --skip-ignore ../../tools/ts_library_builder/main.ts --basePath ../../ --inline ../../js/lib.web_assembly.d.ts --buildPath . --outFile gen/cli/lib/lib.deno_runtime.d.ts --silent --debug
../../js/io.ts:6:26 - error TS4025: Exported variable 'EOF' has or is using private name 'Deno'.
6 export const EOF: typeof Deno.EOF = Deno.EOF;
~~~~
@ry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kt3k Sounds good. I expect we might have to adjust this a bit before the release.
I've pushed denoland/std#527 to the branch https://github.com/denoland/deno_std/tree/20190705_update_reader so that it's advertised.
Thanks for pushing through this interface change!
Changing the EOF symbol to a "const string" may seem smart from a typing perspective, but it's obviously bad in practice. let line: string | EOF = reader.readLine();
if (line === EOF) { explode() } What happens if the file contains a line "EOF" ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@piscisaureus makes a good point.
Can't we just put in some hack somewhere where it adds at the beginning of lib.deno_runtime.d.ts
declare Deno.EOF: unique symbol;
export type EOF = typeof Deno.EOF;
(cc @kitsonk )
@piscisaureus @ry Another workaround suggestion. How about making Deno.EOF null type (as temporary solution)? This seems working and doesn't seem affecting current use cases in deno_std. (and it doesn't require the changes of ts_library_builder) export const EOF: null = null;
export type EOF = null; |
@kt3k Sounds good |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
In #2335 a conditional was added to make sure toAsyncIterator didn't skip chunks because the reader returned data and EOF in a single call, fixing #2330. Later, in #2591, the `Reader` interface changed to `Promise<number | EOF>`. Since the reader no longer returns data and EOF in a single call, this conditional is not necessary. We can just return `{ done: true }` when we get `EOF`. Co-authored-by: Arun Srinivasan <[email protected]> Co-authored-by: Arun Srinivasan <[email protected]>
This PR changes the Reader interface from:
to:
I introduced
EOF
symbol according to @bartlomieju's comment and the discussion in denoland/std#444closes #2384