Execution Model
Lifecycle
Weaver's execution model is simple yet orderly, ensuring all controllers and services will be ready as soon as their respective hosts start Weaver.
- Weaver is required
- WeaverServices and WeaverControllers are created
WeaverServer.Start()
andWeaverClient.Start()
respectively are called- Weaver internally constructs the services when
WeaverServer.Start()
is called
- Weaver internally constructs the services when
- Every
WeaverInit
method is invoked- Weaver waits for all respective
WeaverService:WeaverInit()
andWeaverController:WeaverInit()
methods to resolve before continuing to the next step
- Weaver waits for all respective
- Every
WeaverStart
method is invoked, spawning new threads for all services and controllers - All threads yielding from
WeaverServer.OnStart()
andWeaverClient.OnStart()
respectfully are resumed
Explanation
When WeaverServer.Start()
is called, all of the WeaverServices are instantiated internally, which includes RemoteSignals and methods. This step does not happen on the client, rather, services are dynamically created when WeaverClient.GetService()
is called.
Internally, all services' signals and their attributes are guaranteed to be ready when they are returned using WeaverClient.GetService()
. This is because they are created before WeaverInit, as other services may use or rely on a service's RemoteSignals during WeaverInit or WeaverStart. This is the same for how WeaverControllers behave, just without creating instances.
WeaverServices and WeaverControllers are unable to be created once their respective hosts have started Weaver.
Best Practice
When using Weaver, your project structure should generally follow these rules:
- One script on the server manages the WeaverServer
- This means that all service modules should be used in one script, alongside
WeaverServer.Start()
- This means that all service modules should be used in one script, alongside
- One script on the client manages the WeaverClient
- This means that all controller modules should be used in one script, alongside
WeaverClient.Start()
- This means that all controller modules should be used in one script, alongside
Since Weaver relies on a single-script architecture, it may not work correctly if your project has a multi-script architecture.