module Ably::Modules::AsyncWrapper

Provides methods to convert synchronous operations into async operations through the use of {www.rubydoc.info/github/eventmachine/eventmachine/EventMachine#defer-class_method EventMachine#defer}. The async_wrap method can only be called from within an EventMachine reactor, and must be thread safe.

@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.

@example

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'