Streaming: $response->stream()

The $response->stream($fn) primitive gives you fine-grained control: $fn receives a $write(string) closure that flushes chunks the moment you call it. Useful when you want to decide what to send at run time instead of yielding a fixed sequence.

How it's wired (route side)

$app->route('/stream/words', function ($response) {
    return $response->stream(function ($write) {
        foreach (explode(' ', 'streamed word by word from the server') as $w) {
            $write($w . ' ');
            co::sleep(0.15);  // a real handler waits on real I/O instead
        }
    });
});

Run it

Click Run. Each word arrives as a separate chunk.