--tKW2IUtsqtDRztdT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Feb 08, 2012 at 01:47:31AM +0900, Thomas Sawyer wrote:
> 
> Issue #5978 has been reported by Thomas Sawyer.
> 
> ----------------------------------------
> Bug #5978: YAML.load_stream should process documents as they are read
> https://bugs.ruby-lang.org/issues/5978
> 
> Author: Thomas Sawyer
> Status: Open
> Priority: Normal
> Assignee: 
> Category: 
> Target version: 2.0.0
> ruby -v: ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]
> 
> 
> Psych say YAML.load_documents is deprecated and say to use `YAML.load_stream` instead.
> 
> Looking at the implementation for `load_stream()`, looks to me as if it waits for all documents in the stream to load before anything can be done with it.
> 
>     # File 'lib/psych.rb', line 221
> 
>     def self.load_stream yaml
>       parse_stream(yaml).children.map { |child| child.to_ruby }
>     end
> 
> I don't think this should be the case. Ideally `load_stream()` would takelock, and if an IO object is given, read a document, yield it and then read the next document, and so on.
> 
> I imagine an Enumerator might be applicable to this as well.

I'd rather not change `load_stream`, but I want this functionality as
well.  What about something like this:

  YAML::Reader.new(io).each do |doc|
    ...
  end

Deserialized documents will be yielded as read.  Does that seem
acceptable?  I'm hesitant to make it enumerable though because if we're
truly doing stream processing, you couldn't iterate on the same object
twice (imagine reading YAML from a socket or something).

-- 
Aaron Patterson
http://tenderlovemaking.com/

--tKW2IUtsqtDRztdT
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)

iQEcBAEBAgAGBQJPMqypAAoJEJUxcLy0/6/GVMQH/0RtH1S1eV4/67Bzc0MU8vnD
l6qDUKfaVX7mZpYdUAfJ/uMzdMMTA8PV8UUnMjsjyqFuXWT8PrqBBj2GKja9mAIQ
1UKSkcvv7TOuiLBh6MZWG+Tggy8MPKVYToT5KGiddavNfsmMu5wSQw4iml27f0BT
paJxh7TljmWrTihbPferKE99mSg2FFrm54B+TnDoXtrSmg0q4nSITSwpozNr+TBM
3ZWIkG+zmZ4K1Dm8QhIV5dvtXmAxbAMkWXX8Bdcm40S8knA1V+/bFIiIsi5I21Xn
54emRMTGMtAEmTM4cmPnUzYXvt1FiG9+KaOIY6XLSFDBUfIA8Ypq1pD++EyAfa08H
-----END PGP SIGNATURE-----

--tKW2IUtsqtDRztdT--