On Tue, Mar 26, 2013 at 2:40 PM, Michael Jackson <[email protected]>wrote:

> On Mon, Mar 25, 2013 at 4:53 PM, Mikeal Rogers <[email protected]>wrote:
>
>>
>> On Mar 25, 2013, at 4:40PM, Michael Jackson <[email protected]> wrote:
>>
>> (well, pausing seems to work a lot better now)
>>
>>
>> Is this true?
>>
>> In request I'm just abusing the backwards compatibility mode by calling
>> .resume() on stuff a lot.
>>
>
> I ran quite a few tests on various node core streams last night and this
> morning and it seems that pause/resume actually do what they're supposed to
> in 0.10. Streams start out "paused" so you shouldn't need to pause/resume
> yourself. At least in every case that I can think of.
>
> However, until #5141 <https://github.com/joyent/node/issues/5141> is
> fixed the most reliable way to read from a stream is still the "data"
> event, not "readable" and stream.read. To illustrate, here is the simplest
> example that I can come up with to reliably buffer the entire contents of a
> stream in 0.10, whether called immediately or after some IO has occurred.
>

You're still doing it wrong. This is like complaining that you can't tell a
stream is ended because you waited to attach an `end` event handler. If
you've deferred to the event loop you have to check if a stream isn't ended
first. Likewise, you should call read and, only when it's exhausted, add a
readable handler. Here's your example from the issue you filed reworked to
use an adaption of code ripped strait from a streams2 example (totally
untested, of course):

    var http = require('http');

    http.get('http://joyent.com/', function (response) {
      setTimeout(function () {

        function flow() {
          var chunk;
          while ((chunk = response.read()).length) {
            doSomething(chunk);
          }
          response.once('readable', flow);
        }
        flow();

        response.on('end', function () {
          // oh noes -- using this contrived example this event could be
missed too!
          console.log('end');
        });
      }, 10);
    });

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to