Module: HashiCorp::VagrantVMwareDesktop::Helper::Lock

Defined in:
lib/vagrant-vmware-desktop/helper/lock.rb

Overview

The Lock module implements some locking primitives for parallelism that respect the Vagrant version that is available.

Class Method Summary collapse

Class Method Details

.lock(machine, name, **opts, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vagrant-vmware-desktop/helper/lock.rb', line 10

def self.lock(machine, name, **opts, &block)
  # Before version 1.6, we don't have any sort of locking
  return block.call if Vagrant::VERSION < "1.6.0"

  # Set some defaults
  opts = { retry: true }.merge(opts)

  # Lock the environment and yield it.
  begin
    return machine.env.lock(name, &block)
  rescue Vagrant::Errors::EnvironmentLockedError
    raise if !opts[:retry]
    sleep 1
    retry
  end
end