Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 69cdfa1

Browse files
committedNov 8, 2013
Fix break in Enumerator
Now we support infinite enumerators
1 parent 1585e3d commit 69cdfa1

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed
 

Diff for: ‎opal/core/enumerator.rb

+20-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,31 @@ def initialize(enumerator, block, to)
99
end
1010

1111
def yield(*values)
12-
@to.call(*values)
12+
%x{
13+
if ($opal.$yieldX(#@to, values) === $breaker) {
14+
throw $breaker;
15+
}
16+
}
17+
18+
self
1319
end
1420

1521
alias << yield
1622

1723
def call
18-
@block.call(self)
24+
%x{
25+
try {
26+
#@block(self)
27+
}
28+
catch (e) {
29+
if (e === $breaker) {
30+
return $breaker;
31+
}
32+
else {
33+
throw e;
34+
}
35+
}
36+
}
1937
end
2038
end
2139

0 commit comments

Comments
 (0)
Please sign in to comment.