brianmario / mysql2

A modern, simple and very fast Mysql library for Ruby - binding to libmysql
http://github.com/brianmario/mysql2
MIT License
2.24k stars 550 forks source link

Streaming results... asynchronously. #1034

Open ioquatix opened 5 years ago

ioquatix commented 5 years ago

I'm the developer of async and also working on async-mysql. It's a little bit similar to EventMachine but uses fibers.

I've been trying to make mysql2 work well with async. async_result is okay except it appears it could still block internally when reading large result sets.

So, I wanted to try streaming to improve the situation..

I wish there was an API like Result#next which returned the next rows without requiring to call #each with a block.

I wish there was a was some way to tell if the next call to Result#next would block on network I/O. e.g. Result#available?.

Ideally, I can write something like this:

client.query(sql, async: true, stream: true, **options)

wait_readable
result = client.async_result

# Read one row:
wait_readable unless result.available?
return result.next

Do you think something like this is possible?

sodabrew commented 5 years ago

Yes! I've been thinking about this for a while. #600 has some thoughts noted.

ioquatix commented 5 years ago

If you can implement the above interface, I can test it using async.