Module: ZeevexConcurrency::Delayed::Bindable

Included in:
ZeevexConcurrency::Delay, Future, Promise
Defined in:
lib/zeevex_concurrency/delayed.rb

Instance Method Summary collapse

Instance Method Details

#bind(proccy = nil, &block) ⇒ Object

Raises:

  • (ArgumentError)


186
187
188
189
190
191
192
193
# File 'lib/zeevex_concurrency/delayed.rb', line 186

def bind(proccy = nil, &block)
  raise "Already bound" if bound?
  if proccy && block
    raise ArgumentError, "must supply a callable OR a block or neither, but not both"
  end
  raise ArgumentError, "Must provide computation as proc or block" unless (proccy || block)
  @binding = proccy || block
end

#bindingObject



182
183
184
# File 'lib/zeevex_concurrency/delayed.rb', line 182

def binding
  @binding
end

#bound?Boolean

Returns:

  • (Boolean)


178
179
180
# File 'lib/zeevex_concurrency/delayed.rb', line 178

def bound?
  !! @binding
end

#callObject



203
204
205
# File 'lib/zeevex_concurrency/delayed.rb', line 203

def call
  execute
end

#executeObject



195
196
197
198
199
200
201
# File 'lib/zeevex_concurrency/delayed.rb', line 195

def execute
  @exec_mutex.synchronize do
    return if executed?
    return if respond_to?(:cancelled?) && cancelled?
    _execute(binding)
  end
end