Sha256: ce61b3e16b848b516fba43c8f5373196a8c498a45d716d1fe240db15029f68ec

Contents?: true

Size: 788 Bytes

Versions: 82

Compression:

Stored size: 788 Bytes

Contents

require 'eventmachine'

module Ably::Modules
  # EventMachineHelpers module provides common private methods to classes simplifying interaction with EventMachine
  module EventMachineHelpers
    private

    # This method allows looped blocks to be run at the next EventMachine tick
    # @example
    #   x = 0
    #   less_than_3 = -> { x < 3 }
    #   non_blocking_loop_while(less_than_3) do
    #     x += 1
    #   end
    def non_blocking_loop_while(lambda_condition, &execution_block)
      if lambda_condition.call
        EventMachine.next_tick do
          if lambda_condition.call # ensure condition is still met following #next_tick
            yield
            non_blocking_loop_while(lambda_condition, &execution_block)
          end
        end
      end
    end
  end
end

Version data entries

82 entries across 82 versions & 2 rubygems

Version Path
ably-1.0.3 lib/ably/modules/event_machine_helpers.rb
ably-1.0.2 lib/ably/modules/event_machine_helpers.rb
ably-1.0.1 lib/ably/modules/event_machine_helpers.rb
ably-rest-1.0.0 lib/submodules/ably-ruby/lib/ably/modules/event_machine_helpers.rb
ably-1.0.0 lib/ably/modules/event_machine_helpers.rb
ably-rest-0.8.15 lib/submodules/ably-ruby/lib/ably/modules/event_machine_helpers.rb
ably-0.8.15 lib/ably/modules/event_machine_helpers.rb
ably-rest-0.9.3 lib/submodules/ably-ruby/lib/ably/modules/event_machine_helpers.rb
ably-rest-0.9.2 lib/submodules/ably-ruby/lib/ably/modules/event_machine_helpers.rb
ably-rest-0.9.1 lib/submodules/ably-ruby/lib/ably/modules/event_machine_helpers.rb
ably-rest-0.9.0 lib/submodules/ably-ruby/lib/ably/modules/event_machine_helpers.rb
ably-rest-0.8.14 lib/submodules/ably-ruby/lib/ably/modules/event_machine_helpers.rb
ably-0.8.14 lib/ably/modules/event_machine_helpers.rb
ably-rest-0.8.13 lib/submodules/ably-ruby/lib/ably/modules/event_machine_helpers.rb
ably-0.8.13 lib/ably/modules/event_machine_helpers.rb
ably-0.8.12 lib/ably/modules/event_machine_helpers.rb
ably-0.8.11 lib/ably/modules/event_machine_helpers.rb
ably-0.8.10 lib/ably/modules/event_machine_helpers.rb
ably-rest-0.8.9 lib/submodules/ably-ruby/lib/ably/modules/event_machine_helpers.rb
ably-0.8.9 lib/ably/modules/event_machine_helpers.rb