VContainer + UniTask
UniTask is a library that brings fast and powerful async/await to the Unity world.
If you have the com.cysharp.unitask
package installed in your project, the following features will be enabled.
#
IAsyncStartableWe can create an entry point for the async UniTask.
By creating a class like the one above and Registering it, the UniTask of StartAsync will be executed automatically.
For more information about RegisterEntryPoint, please check here.
#
StartAsync() timingThe only async interface provided by VContainer is IAsyncStartable. UniTask can control the execution timing within the async method.
If you want to schedule the process at different times, you can use UniTask's PlayerLoopTiming.
See https://github.com/Cysharp/UniTask#playerloop
#
Exception Handling- Within the async method, try/catch can be used.
- We can use
UniTaskScheduler.UnobservedTaskException
event. - Alternatively, if you want to register a separate error handler for each LifetimeScope, use:
builder.RegisterEntryPointExceptionHandler(ex => ..)
- See Entry point section for more information.
#
CancellationTokenThe argument of StartAsync will be a cancellationToken.
This cancellationToken will be canceled when the LifetimeScope is destroyed.
#
Async asset loadingUniTask supports the ability to load assets and scenes asynchronously. This is useful when used with LifetimeScope.Enqueue* in VContainer.
See Scoping secion for more information.