-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rx.Observable.from..take does not close iterator #1938
Comments
Output:
|
Okay, so the more I think about this, the more I think it might be a feature request more than a bug.
|
I think the real ask here is that we add Observable.spawn(function* () { yield 1; yield 2; yield 3; }); |
@vadzim a temporary solution to this would be to use const g = (function* () { /* stuff */ }());
Observable.from(g)
.take(2)
.finally(() => g.return())
.subscribe(/* stuff */); I hope that's helpful. |
Okay, my several thoughts. I mean, if I can write the code
I know that Some fantastic example.
Of course, this is not a real code. But its purpose is to demonstrate that finalizing resources can be very critical. I believe that if someone wants to control smth in some non-standard way, he must be able to do this, but he must do it manually, that is to call 3.2. As I understood, the spirit of Rx is to call function per every subscription. Not to proceed running function, but to call it once again. So when I look at calling generator I expect that its call is finite, that generator will be finished. Si I expect that |
It's important to note that with |
If someone definitely wants not to close generator, he can hide
I believe that hiding |
Okay. I ask you to think about consistency one more time, please :) |
Otherwise, using Rx with generators can be like a hidden bomb. You can end up with bugs when you start to use Rx instead of |
@vadzim I'm still looking into it. I'm going to model it after how const G = function *() {
try {
let i = 0;
while (true) {
console.log('yielding ' + i);
yield i++;
}
} catch(err) {
console.log('error block', err);
} finally {
console.log('finalized');
}
}
const g = G();
for(let x of g) {
console.log('> ' + x);
if (x === 1) {
break;
}
}
/**
"yielding 0"
"> 0"
"yielding 1"
"> 1"
"finalized"
*/ Although I do find it odd behavior because the |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
RxJS version: 5.0.0-beta.12
NodeJS version: 6.5.0
Code to reproduce:
Expected behavior:
Actual behavior:
Additional information:
Following native code closes iterator properly:
Output:
The text was updated successfully, but these errors were encountered: