Question

Is it possible to replace all ruby IO clases with different implementation, that uses reactor and fibers behind the scene? I mean that in fact all libraries, that uses native ruby IO will work as expected, because of all calls to IO will be wrapped with fibers, and they will wait for requested operation. But while waiting when data is available in connection/file ruby will serve other io operations.

Was it helpful?

Solution

Is it posible? Yes, just monkey-patch IO. Is it a lot of work? Yes, but if you really want it, do it. If you don't know how to monkey patch IO, make that your question.

For example, to override read:

class IO
  def read(count = -1)
    #Some fiber code here...
  end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top