Skip to content

Streams closed while data still in buffer #49

@calcinai

Description

@calcinai

Hey, Not sure if this is desired behaviour or not, but I've run into an issue where the data in the buffer doesn't ever get written.

As per example:

$connector->create('www.google.com', 80)->then(function (React\Stream\Stream $stream) {
    $stream->write('...');
    $stream->close();
});

From what I can see, the $stream->write() appends the data to the buffer and doesn't do a lot else at that point; it waits for the next tick of the event loop to come and write the buffer out. Because of that, when you follow it immediately with $stream->close(), it closes it and flushes the buffer.

As I said, I'm not sure if this is expected behaviour, and I can see benefits in both. As a work around, I'm doing this:

$connector->create('www.google.com', 80)->then(function (Stream $stream) use ($template) {
    $stream->write('');
    $stream->getBuffer()->on('full-drain', function() use($stream) {
        $stream->close();
    });
});

Is this as simple as a doc update?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions