Class: Conflow::Future

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

Overview

Struct like objects that represent value to be returned by Job

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job, result_key = nil) ⇒ Future

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Future.

Parameters:

  • job (Conflow::Job)

    Job which result is promised

  • result_key (String, Symbol) (defaults to: nil)

    key under which promised value exists

See Also:



25
26
27
28
# File 'lib/conflow/future.rb', line 25

def initialize(job, result_key = nil)
  @job = job
  @result_key = result_key
end

Instance Attribute Details

#jobObject (readonly)

Job which result is promised



17
18
19
# File 'lib/conflow/future.rb', line 17

def job
  @job
end

#result_keyObject (readonly)

Key in the result hash to which this future proxies



19
20
21
# File 'lib/conflow/future.rb', line 19

def result_key
  @result_key
end

Instance Method Details

#[](key) ⇒ Future

Returns new Conflow::Future with assigned key, if possible

Examples:

job = run AJob #=> returns { email: "[email protected]" }
job.outcome[:email] # when resolved, will return "[email protected]"

Parameters:

  • key (Symbol, String)

    Key in result hash of the job that holds promised value

Returns:

  • (Future)

    future object that can be used as parameter

Raises:



36
37
38
39
# File 'lib/conflow/future.rb', line 36

def [](key)
  raise InvalidNestedFuture if result_key
  Future.new(job, key)
end

#build_promise(depending_job, param_key) ⇒ Conflow::Promise

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Builds promise from this future

Parameters:

  • depending_job (Conflow::Job)

    job which will use new promise

  • param_key (Symbol, String)

    key in result hash that holds promised value

Returns:



46
47
48
49
50
51
# File 'lib/conflow/future.rb', line 46

def build_promise(depending_job, param_key)
  Promise.new.tap do |promise|
    promise.assign_attributes(job_id: job.id, hash_field: param_key, result_key: result_key)
    depending_job.promise_ids << promise.id
  end
end