Sha256: 310f1fc0fea28f0a5f47667deb086f07fa0524e75c941a1133c2f305e257c330
Contents?: true
Size: 1 KB
Versions: 1
Compression:
Stored size: 1 KB
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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
concurrent-ruby-0.2.1 | lib/concurrent/utilities.rb |