Skip to content

Commit

Permalink
Fix break in Enumerator
Browse files Browse the repository at this point in the history
Now we support infinite enumerators
  • Loading branch information
meh committed Nov 8, 2013
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
Expand Up @@ -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

Expand Down

0 comments on commit 69cdfa1

Please sign in to comment.