Skip to content

Commit

Permalink
Rename Promise#collect to #trace
Browse files Browse the repository at this point in the history
  • Loading branch information
meh committed Dec 26, 2013
1 parent 09e084c commit a79052a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
@@ -1,20 +1,20 @@
require 'promise'

describe 'Promise#collect' do
describe 'Promise#trace' do
it 'calls the block with all the previous results' do
x = 42

Promise.value(1).then { 2 }.then { 3 }.collect {|a, b, c|
Promise.value(1).then { 2 }.then { 3 }.trace {|a, b, c|
x = a + b + c
}

x.should == 6
end

it 'calls the then after the collect' do
it 'calls the then after the trace' do
x = 42

Promise.value(1).then { 2 }.then { 3 }.collect {|a, b, c|
Promise.value(1).then { 2 }.then { 3 }.trace {|a, b, c|
a + b + c
}.then { |v| x = v }

Expand All @@ -26,7 +26,7 @@

Promise.value(1).then {
Promise.when Promise.value(2), Promise.value(3)
}.collect {|a, b|
}.trace {|a, b|
x = a + b[0] + b[1]
}

Expand Down
8 changes: 4 additions & 4 deletions stdlib/promise.rb
Expand Up @@ -174,8 +174,8 @@ def always(&block)
alias finally always
alias ensure always

def collect(&block)
self ^ Collect.new(block)
def trace(&block)
self ^ Trace.new(block)
end

def inspect
Expand All @@ -194,7 +194,7 @@ def inspect
result
end

class Collect < self
class Trace < self
def self.it(promise)
unless promise.realized?
raise ArgumentError, "the promise hasn't been realized"
Expand All @@ -211,7 +211,7 @@ def self.it(promise)

def initialize(block)
super -> {
block.call(*Collect.it(self).reverse)
block.call(*Trace.it(self).reverse)
}
end
end
Expand Down

0 comments on commit a79052a

Please sign in to comment.