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

Add flush to many builders #8876

Merged
merged 1 commit into from
Mar 9, 2020
Merged

Add flush to many builders #8876

merged 1 commit into from
Mar 9, 2020

Conversation

asterite
Copy link
Member

@asterite asterite commented Mar 4, 2020

Fixes #8875

Sorry that there are no specs but it's a bit cumbersome to test. Plus it's really easy to see what's going on.

@@ -244,7 +245,7 @@ module YAML
end

# Writes YAML into the given `IO`. A `YAML::Builder` is yielded to the block.
def self.build(io : IO)
def self.build(io : IO) : Nil
Copy link
Contributor

Choose a reason for hiding this comment

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

No io.flush here?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, because YAML::Builder already does that.

Copy link
Member

Choose a reason for hiding this comment

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

Why does YAML::Builder flush but XML::Builder doesn't? Shouldn't we make this behave identical?
JSON::Builder#flush delegates to io.flush which is another different behaviour.

Copy link
Member Author

Choose a reason for hiding this comment

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

I noticed that too. I didn't want to start making changes all over the place. That's why I added flush when needed.

Also, maybe this PR is not needed...

@@ -49,9 +49,10 @@ class YAML::Builder

# Creates a `YAML::Builder` that will write to the given `IO`,
# invokes the block and closes the builder.
def self.new(io : IO)
def self.new(io : IO) : Nil
Copy link
Member

Choose a reason for hiding this comment

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

General question: Should this method be named build? It's not a constructor and doesn't return an instance of YAML::Builder which I'd usually expect from a .new method.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I was surprised by this name too. We could probably rename it, but I'd like to avoid doing that in this PR.

@Sija
Copy link
Contributor

Sija commented Mar 5, 2020

I love the branch name, btw 🤣

@bcardiff bcardiff added this to the 0.34.0 milestone Mar 9, 2020
@bcardiff bcardiff merged commit c65610a into master Mar 9, 2020
Sija added a commit to Sija/gphoto2-web that referenced this pull request Jul 13, 2020
@Sija
Copy link
Contributor

Sija commented Jul 16, 2020

Hmm, I believe I've found out one possible regression: calling #to_json/yaml on HTTP::Server::Response will flush the underlying io, making it impossible to modify the response afterwards (thinking headers) before closing or passing it further on.

@Blacksmoke16
Copy link
Member

Related #8712.

@Darimac1

This comment has been minimized.

@Blacksmoke16

This comment has been minimized.

@Darimac1

This comment has been minimized.

@Sija

This comment has been minimized.

@asterite

This comment has been minimized.

@Darimac1 Darimac1 mentioned this pull request Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incomplete CSV file if writing a file with CSV module
7 participants