Class: Dharma::Future

Inherits:
Object
  • Object
show all
Defined in:
lib/dharma/future.rb

Class Method Summary collapse

Class Method Details

.call(body, executor) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dharma/future.rb', line 3

def self.call(body, executor)
  promise = Dharma.promise

  work = proc do
    begin
      promise.success(body.call)
    rescue => e
      promise.failure(e)
    end
  end

  executor.execute(work)

  promise
end