#Interval emitting after unsubscribing with takeUntil

13 messages · Page 1 of 1 (latest)

white lynx
#

I want interval to stop emitting values after game$ observable emits but instead it does one extra loop. Is there any way to stop this behaviour

#

Interval emitting after unsubscribing with takeUntil

hardy trench
#

What happens one extra time? Your grid assigning? If yes, you should try to split the grid assigning + checkFor… in two different taps

#

Btw assigning/reassigning an external value within a stream is a bad practice, you should try to find another way to proceed (Like making a grid$ stream with a map instead of that tap with assigning)! You may not see any issue doing that and it may work, but sooner or later you will find out that it is not a good thing to do.

white lynx
#

I moved chekFor... in another tap but i get the same issue. After game$ emits tick$ should end i think but instead it emits one more time so snake gets out of border.

white lynx
#

It looks like takeUntil was working just fine and the issue was where i was updating snake...

hardy trench
#

Yeah that’s a timing issue. It happens quite often when you do some imperative code with observables

#

Could you fix it?

white lynx
#

Yes!

#

Btw is it better to use declarative with observables? @hardy trench

hardy trench
#

Yes it is!

#

First of all, declarative is more "complete" thanks to reactive programming + the gain in term of readability is huge! You won't fear CTRL CLICKs on some variable used 4572 times in many files

white lynx
#

Thank you