Skip to content

The ClientEngine.start() promise is not resolved #124

@T-vK

Description

@T-vK

Can we please change the code of ClientEngine.start so that it resolves once it's ready?

I was extremely confused that this just wouldn't work:

export default class MyGameClientEngine extends ClientEngine {
    // ...
    async start() {
        await super.start(); // Execution stops right here
        this.gameEngine.once('renderer.ready', () => {
            // ...
            document.querySelector('#joinGame').addEventListener('click', (clickEvent) => {
                console.log("CLICK #joinGame");
                if (Utils.isTouchDevice()){
                    this.renderer.enableFullScreen();
                }
                clickEvent.currentTarget.disabled = true;
                this.socket.emit('requestRestart');
            });
            // ...
        });
        // ...
    }
    // ...
}

Or this:

const clientEngine = new MyGameClientEngine(gameEngine, options);
clientEngine.start().then(()=>{
    // This doesn't get executed because `ClientEngine.start` doesn't resolve
    clientEngine.renderer.setupBackground();
    clientEngine.renderer.setRendererSize();
}).catch(console.error); 

It seems like a very bad idea to not resolve the promise immediately. (Not to mention that rejecting with undefined makes debugging a nightmare.)

I'd be willing to make a PR, but I wanted to discuss this first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions