Sha256: 7773a03a7c12f231c5a5c46c33e269037304cb5d8c5a5e5987a6f96814a3682f

Contents?: true

Size: 995 Bytes

Versions: 4

Compression:

Stored size: 995 Bytes

Contents

module Kernel

  # Perform the given block as though it were an atomic operation. This means
  # that the Ruby scheduler cannot premept the block and context switch to
  # another thread. Basically a light wrapper around Ruby's Fiber class.
  #
  # @note Be very careful about what operations you perform within an atomic
  # block. Blocking operations such as I/O should *never* occur within an
  # atomic block. In those cases the entire Ruby VM will lock until the
  # blocking operation is complete. This would be bad.
  #
  # @yield calls the block
  # @yieldparam args an arbitrary set of block arguments
  #
  # @param [Array] zero more more optional arguments to pass to the block
  def atomic(*args)
    raise ArgumentError.new('no block given') unless block_given?
    return Fiber.new {
      yield(*args)
    }.resume
  end
  module_function :atomic
end

class Mutex

  def sync_with_timeout(timeout, &block)
    Timeout::timeout(timeout) {
      synchronize(&block)
    }
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
concurrent-ruby-0.2.2 lib/concurrent/utilities.rb
concurrent-ruby-0.2.0 lib/concurrent/utilities.rb
concurrent-ruby-0.1.1.pre.5 lib/concurrent/utilities.rb
concurrent-ruby-0.1.1.pre.4 lib/concurrent/utilities.rb