Method: Lalka::Task#bind
- Defined in:
- lib/lalka.rb
#bind(*args, &block) ⇒ Object Also known as: chain, flat_map
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/lalka.rb', line 70 def bind(*args, &block) block = function_from_arguments(*args, &block) Task.new do |t| fork do |this| this.on_success do |first_value| other_task = block.call(first_value) other_task.fork do |other| other.on_success do |second_value| t.resolve(second_value) end other.on_error do |error| t.reject(error) end end end this.on_error do |error| t.reject(error) end end end end |