Reputation: 1819
I'm serving binary data from a Play 1.2.x app. Due to hardware constraints on the client (slow processor and small amount of RAM), just writing chunks of 256 bytes one after another did not work. The naive solution is to use a timeout between the chunks like this:
while(we have chunks to write) {
response.writeChunk(aChunk);
Thread.sleep(250);
}
This works fine but obviously is a bad idea since we're hogging the whole server with the call to sleep.
Is there a correct way of doing this in Play 1.2.x?
Upvotes: 0
Views: 160
Reputation: 2273
If your code is executing in a controller, you can use the await() function.
while(we have chunks to write) {
response.writeChunk(aChunk);
await(250);
}
This will not block the main play-thread.
Upvotes: 3