peterszombati / xapi-node

xStation5 Trading API for NodeJS/JS
https://peterszombati.github.io/xapi-node/
Other
58 stars 19 forks source link

XAPI.onReady() method being called endlessly for no reason #8

Closed kkollman closed 3 years ago

kkollman commented 3 years ago

Hi there!

I have noticed strange behavior while using the .onReady method - it gets called randomly, twice each time.

In the example below, this.fetcher is an instance of XAPI reused in another class:

connectToMarket = (): void => {
        this.fetcher.connect();

        this.fetcher.onReady(() => {
            let now = new Date();
            console.log(
                'Fetcher is connected and ready',
                now.getHours(),
                ':',
                now.getMinutes(),
                '.',
                now.getSeconds()
            );
        });
    };

This gives me an output:

Fetcher is connected and ready 18 : 49 . 31
Fetcher is connected and ready 18 : 49 . 31
Fetcher is connected and ready 18 : 49 . 44
Fetcher is connected and ready 18 : 49 . 44
Fetcher is connected and ready 18 : 50 . 35
Fetcher is connected and ready 18 : 50 . 35
Fetcher is connected and ready 18 : 51 . 28
Fetcher is connected and ready 18 : 51 . 28
Fetcher is connected and ready 18 : 52 . 19
Fetcher is connected and ready 18 : 52 . 19
Fetcher is connected and ready 18 : 53 . 13
Fetcher is connected and ready 18 : 53 . 13

Any idea what can be causing that?

kkollman commented 3 years ago

I may possibly have discovered why the double output, yet still no idea why onready gets called over and over

kkollman commented 3 years ago

Okay, nevermind - I have discovered flaws in my code that caused it! :)

peterszombati commented 3 years ago

@kkollman still no one find a bug in this module :D