rxjs-spy icon indicating copy to clipboard operation
rxjs-spy copied to clipboard

spy.show() doesn't filter out observables that run in sync

Open jecraig opened this issue 6 years ago • 6 comments

When using spy.show() from the console, observables that run synchronously are not filtered out of the list.

const asyncSub = new AsyncSubject();
asyncSub.next(null);
asyncSub.complete();

asyncSub.pipe(tag('nodelay.1')).subscribe();
asyncSub.pipe(tag('nodelay.2')).subscribe();

asyncSub
	.pipe(
		tag('delay.1'),
		delay(1),
	)
	.subscribe();

asyncSub
	.pipe(
		tag('delay.2'),
		delay(1),
	)
	.subscribe();

spybug

jecraig avatar Feb 21 '19 03:02 jecraig

Why is that a problem? It states that they are complete. There will be more advanced querying capabilities in rxjs-devtools, but this is not something that I intend to fix/change here.

Completed subscriptions will continue to be shown until the keptDuration elapses.

cartant avatar Feb 21 '19 04:02 cartant

I've actually got keptDuration set to zero in the demo. So they should have been wiped. As you can see, the other two tags were removed and they subscribed after the synchronous ones.

The issue is I'm combing through my site looking for any leaky subscriptions. Since the synchronous ones aren't removed, they become red-herrings. A work around is to add a delay(1) to the pipe, but that's altering code to fix a debug tool.

Also, I understand you're working on rxjs-devtools. I'm mostly logging this because it dogged me for two days and I'm hoping to spare others.

jecraig avatar Feb 21 '19 04:02 jecraig

Try setting it to a small, non-zero number.

cartant avatar Feb 21 '19 04:02 cartant

I'll add your synchronous AsyncSubject scenario as a test in rxjs-devtools is it's a problem there and the same solution applies to rxjs-spy, I will fix it.

cartant avatar Feb 21 '19 05:02 cartant

I added some sync tests for the graph flushing to rxjs-devtools and they passed. I've added the same tests here and they too pass. I'm not going to look further into this because although the graphing implementation is pretty much unchanged, the snapshotting implementation in rxjs-devtools is completely different.

cartant avatar Feb 21 '19 09:02 cartant

FYI, I've added tests to rxjs-devtools to determine whether or not snapshots for completed subscriptions are flushed correctly when snapshotting - based on the keptDuration - and, yes, they appear to be.

cartant avatar Feb 22 '19 06:02 cartant