Summary: This article addresses questions regarding the behavior of asynchronous functions in Cloud Code (JS or C#) and their impact on execution time and billing.
Title: Cloud Code Asynchronous Execution
Symptoms:
- Uncertainty about whether an asynchronous function (like logHelper()) will complete after the main function returns in Cloud Code.
- Questions regarding the impact of asynchronous functions on execution time and billing.
- Q. "What happens to an Asynchronous Call after the main method completes, in Cloud Code?"
Cause: The user is seeking to understand the behavior of asynchronous functions in Cloud Code, as it relates to runtime, and billing.
Resolution:
1. Asynchronous functions in Cloud Code will generally complete even if the main function has returned, but this is not guaranteed. There is a cutoff that can lead to the termination of the Cloud Code process, affecting both the main and asynchronous methods consistently.
2. An Asynchronous function can run for longer than the normal 15 seconds soft cutoff, but there is a hard cutoff. Unity cannot guarantee that an asynchronous function that goes beyond the main thread will complete, but generally it is very likely to complete.
3. Execution time and billing continue while any threads are consuming CPU time, including those from asynchronous functions. Using the Sleep method on a thread means it will not consume CPU time whilst asleep.