Module: Ably::Modules::AsyncWrapper

Overview

Note:

using this AsyncWrapper should only be used for methods that are used less frequently and typically not run with levels of concurrency due to the limited number of threads available to EventMachine by default. This module requires that the method #logger is defined.

Provides methods to convert synchronous operations into async operations through the use of EventMachine#defer. The async_wrap method can only be called from within an EventMachine reactor, and must be thread safe.

Examples:

class BlockingOperation
  include Aby::Modules::AsyncWrapper

  def operation(&success_callback)
    async_wrap(success_callback) do
      sleep 1
      'slept'
    end
  end
end

blocking_object = BlockingOperation.new
deferrable = blocking_object.operation do |result|
  puts "Done with result: #{result}"
end
puts "Starting"

# => 'Starting'
# => 'Done with result: slept'