Skip to content

Commit 24976ef

Browse files
committed
raise exception in next because that seems more correct
1 parent 5509501 commit 24976ef

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/hxcoro/generators/SyncGenerator.hx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ private class GeneratorImpl<T> extends Dispatcher implements IContinuation<Any>
1818
final f:Coroutine<Yield<T> -> Void>;
1919
var nextValue:Null<T>;
2020
var nextStep:Null<IContinuation<T>>;
21+
var raisedException:Null<Exception>;
2122
var resumed:Bool;
2223

2324
public function new(f:Coroutine<Yield<T> -> Void>) {
@@ -44,13 +45,18 @@ private class GeneratorImpl<T> extends Dispatcher implements IContinuation<Any>
4445
}
4546

4647
public function next() {
48+
if (raisedException != null) {
49+
resumed = true;
50+
throw raisedException;
51+
}
4752
return nextValue;
4853
}
4954

5055
public function resume(result:Null<Any>, error:Null<Exception>) {
51-
resumed = true;
5256
if (error != null) {
53-
throw error;
57+
raisedException = error;
58+
} else {
59+
resumed = true;
5460
}
5561
}
5662

0 commit comments

Comments
 (0)