Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix break in Enumerator
Browse files Browse the repository at this point in the history
Now we support infinite enumerators
meh committed Nov 8, 2013

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 1585e3d commit 69cdfa1
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions opal/core/enumerator.rb
Original file line number Diff line number Diff line change
@@ -9,13 +9,31 @@ def initialize(enumerator, block, to)
end

def yield(*values)
@to.call(*values)
%x{
if ($opal.$yieldX(#@to, values) === $breaker) {
throw $breaker;
}
}

self
end

alias << yield

def call
@block.call(self)
%x{
try {
#@block(self)
}
catch (e) {
if (e === $breaker) {
return $breaker;
}
else {
throw e;
}
}
}
end
end

0 comments on commit 69cdfa1

Please sign in to comment.