acrylic-origami / HHReactor

Producer-based Reactor for Hack
MIT License
2 stars 0 forks source link

Pending child iterator blocks restarted Producer #5

Closed acrylic-origami closed 7 years ago

acrylic-origami commented 7 years ago

When a Producer is stopped and started again, it does not yield elements until all child iterators (or more precisely the listeners on those iterators (the "drivers")) have ended due to the total detachment. This change was made while removing $this references within methods that touched the $racetrack drivers [to prevent a massive memory leak, see #4] — now, _attach awaits the previous drivers directly as opposed to pushing that responsibility onto the next driver. This saves a reference to $this and some Awaitable acrobatics, but sadly the titled behavior is the result.

The HTTP section of the README example code is a perfect example of this happening:

// Merge stream of requests from ports 80 and 8080
$http_firehose = Producer::merge(Vector{ connection_factory(80), new connection_factory(8080) });

foreach(clone $http_firehose await as $connection) {
    await $connection->write('No, _you_ deal with this');
    break;
}

foreach(clone $http_firehose await as $maybe_connection) {
    $connection = await $maybe_connection;
    // this isn't reached until the port that wasn't requested in the first
    //  `foreach` is hit by a request
}
acrylic-origami commented 7 years ago

Closing for now thanks to 304ea7d, but still wary of soundness (see ae2d9d0).