'Rxjs scan clonned on subscribe

I don't understand something in rxjs. Why is this reproductible example creating a second, reinitialized instance of counter, when someone:

  1. clicks some times on the inc button
  2. then clicks on the second subscribe button
  3. then reclicks some times on the inc button

Why does it look like the accumulator observable was cloned during the second subscribe ? Thanks.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>Reprex rxjs</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.5.5/rxjs.umd.js">
    </script>
</head>
<body>
<button id="inc_button">Click me to increase</button>
<button id="go_button">Start second counter</button>
</div>
<script>
    let score_calc = rxjs
        .fromEvent(document.getElementById('inc_button'), 'click')
        .pipe(rxjs.operators.scan(acc => acc+1, 0));
        
    score_calc.subscribe(x => console.log('score1',x));
    
    rxjs
        .fromEvent(document.getElementById('go_button'), 'click')
        .pipe(rxjs.operators.first())
        .subscribe(()=> score_calc.subscribe(x => console.log('score2',x)));
</script>
</body>
</html>

Note : I'm a JavaScript newbie.



Solution 1:[1]

Ignore would be something like so:

import timeout_decorator

def ignore(func, *args, **kwargs ):
    def main( *args, **kwargs ):
        try:
            return func( *args, **kwargs )
        except TimeoutError as e:
            print( e )
            return []
    return main

@return_lister
@timeout_decorator.timeout(5)
def function_that_times_out():
    input()

function_that_times_out()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1