Asynchronous Array Mapping in Ruby
EventMachine is great, but may require a few fights to get started.
Recently, I wanted to be able to get the sizes of each image in an array using FastImage. It’s fast, but it’s not that fast when you’ve got tens or hundreds of images you’re trying to size at once.
What I needed was an asynchronous map method for Arrays, like this:
EventMachine did not make this easy. After some fighting, here’s what I came up with:
It works (10x speed increase!), but I’d like to believe that there’s got to be an easier way to do this.