This is a timer that only runs if there are entries in an Subject (holding an array), I used it to load/display items after a period of time (instead of having the website render ALL items at once)
publictimer=100;privatecurrentWaitingSubject=newBehaviorSubject([]);privateinterval$$=this.currentWaitingSubject.pipe(filter(ar=>ar.length>0),// only execute when some are waitingswitchMap(ar=>interval(this.timer).pipe(// switch to intervalwithLatestFrom(this.currentWaitingSubject),takeWhile(([_,waitingAr])=>waitingAr.length>0)// until there arent none, auto unsubscribe))).subscribe(([_timer,_currentArray])=>{this.currentWaitingSubject.next(_currentArray.slice(1));});
So how to use this?
Once you have your list of items, you put all IDs into currentWaitingSubject and then subscribe on in and check until that ID you want to show/render isn't anymore in the list (in the Subject)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is a timer that only runs if there are entries in an Subject (holding an array), I used it to load/display items after a period of time (instead of having the website render ALL items at once)
So how to use this?
Once you have your list of items, you put all IDs into
currentWaitingSubject
and then subscribe on in and check until that ID you want to show/render isn't anymore in the list (in the Subject)