[SOLVED] Design question: what is best way to wait for this asset loading

I’m rather new to PlayCanvas and therefore sometimes having troubles to know what is the best way to do something.
Now I have this script to load an asset:

LoadGlbAsset.prototype.initialize = function() {
    utils.loadGlbContainerFromAsset(this.glbAsset, null, this.glbAsset.name, function (err, asset) {
        if (err) {
        var renderRootEntity = asset.resource.instantiateRenderEntity();

It is attached to an entity for which the asset has to be loaded.
An other script on the same entity has to search for some specific childs. Before I can start searching I have to wait unit the asset is loaded. What is the best way to do this?

A: the callback above could call a function in the other script. Seems not so elegant to me.
B: merging the two scripts so that I can do the search in the callback. Also no so elegant.
C: using events?
D: other ways?

I prefer C.

Fire an event when LoadGlbAsset adds the Entity to the scene. Other scripts listen for this event and do stuff when it is added.

See: [SOLVED] Is there any way to get the callback loaded from a glb? - #6 by yaustar

Isn’t there the risck of race conditions?
I mean, suppose the asset loading is super fast. What if the event is send out before the listener is setup?

What I did was insure the listener script was above the loadGLB script in the component

This means that the listener script initialize is called before the loadGLB removing the race condition

The other thing you can do is move the loadGLB loading code to postInitialize instead. That way it would always be called after the scene’s initialize is called.