About BackendApplicationContribution

Hi,

I’m a bit confused about the BackendApplicationContribution behavior.

According to the documentation of BackendApplicationContribution.initialize, “The implementation may be async, however it will still block the initialization step until it’s resolved.” and BackendApplicationContribution.configure, “Called after the initialization of the backend application is complete.”.

With the following code snippet:

import { BackendApplicationContribution } from "@theia/core/lib/node/backend-application";
import { injectable } from "inversify";

@injectable()
export class BackendContrib1 implements BackendApplicationContribution {
    async initialize() {
        console.log("BackendContrib1.initialize START");
        await new Promise(resolve => setTimeout(resolve, 10000));
        console.log("BackendContrib1.initialize END");
    }
}

@injectable()
export class BackendContrib2 implements BackendApplicationContribution {
    async configure() {
        console.log("BackendContrib2.configure START");
        await new Promise(resolve => setTimeout(resolve, 3000));
        console.log("BackendContrib2.configure END");
    }
}

I would expect the following output in the console:

root INFO BackendContrib1.initialize START
root INFO BackendContrib1.initialize END
root INFO BackendContrib2.configure START
root INFO BackendContrib2.configure END

but what I’ve got is:

root INFO BackendContrib1.initialize START
root INFO BackendContrib2.configure START
root INFO BackendContrib2.configure END
root INFO BackendContrib1.initialize END

So it seems that it doesn’t wait for the initialization of all the BackendApplicationContribution before to call configure as indicated in the documentation. Is that intended?

Thanks

Hi @Hanksha,

The documentation does not state that initialize and configure are executed in sequence. Code comments actually hint that they can be executed in an arbitrary order:

You seem to confuse the configure and onStart method, since you reference the documentation of the latter, while using the former in your code.

BackendApplicationContribution.onStart: Called after the initialization of the backend application is complete.

Also, where do you have that one from? It doesn’t say that in the documentation:

Hi @msujew thanks for your anwser,

No that was just a typo sorry, I edited my original post.

That’s not on the documentation of the interface used by clients, take a look here:


“The implementation may be async, however it will still block the initialization step until it’s resolved.”
“Called after the initialization of the backend application is complete.”

If that’s not the case then it can be better indicated in the documentation of the BackendApplicationContribution interface itself.

Hm, I see, it looks like the documentation is contradictory here.

The decision to have initialize and configure run in parallel seems to be deliberate, although not correctly reflected in the JSDoc. @vince-fugnitto Do you have a clue why we don’t await the initialize step?