CodeFly is a gem that I made, that allows you to do parallel / asynchronous programming in Rails.

This is how a classic code looks like:

This is how a flied code looks like:

The first code will take 2.5 sec, but the second will take only 1.5, almost the twice of speed. On the second code, the A and B queries will be executed at the same time (I will assume that your DB have more than 1 core), and the Ruby will be free to execute your own code while these 2 queries are being processed.

The Fly methods are:

  • fly(id) { async code }
  • wait_fly(id_1[, id_2, …]): block until the async codes terminate

To use code fly, add it to your GemFile:

then install with: