YaTimeAPI¶
YaTimeAPI provides time related APIs for users.
Note: Time APIs would only provide time resolution of no larger than 0.1 second.
That means, invoking APIs with time less than 0.1 seconds would lead to truncated results (e.g., WaitFor 0.01 seconds may cause the callback be invoked immediately).Functions¶
number YaTimeAPI.GetTimeElapsedSinceStart()¶
Returnsseconds since the application started
Get the time elapsed since the application started.
Note: This API is not networked. That means when invoked on a client, the returned value would be different from the server.
After all the API only returns the time elapsed since the endpoint (i.e., the server or Yahaha application) starts.
CancelToken YaTimeAPI.WaitFor(number delaySeconds, function callback)¶
Returnsthe handle of the callback registration
Schedule a time event that happens in delaySeconds and register the event callback.
- delaySecondsnumber of seconds after which time event is triggered
- callbackthe procedure to invoke when the time event is triggered
When you need to trigger logic at a specific time, you can use the YaTime.WaitFor method.
| 1 2 3 4 5 |  | 
You can achieve the effect of executing a series of delayed logic by using nested WaitFor calls.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |  | 
CancelToken YaTimeAPI.ScheduleAtInterval(number startSeconds, number intervalSeconds, function callback)¶
Returnsthe handle of the callback registration
Schedule a periodical time event that starts in startSeconds and triggered every intervalSeconds.
Then register the event callback.
- startSecondsnumber of seconds after which periodical time event starts
- intervalSecondsnumber of seconds between consequence triggers of the time event (this value must not be smaller than 0.1)
- callbackthe procedure to invoke when the time event is triggered
When you need to trigger logic periodically, you can use the YaTimeAPI.ScheduleAtInterval method.
| 1 2 3 4 5 6 |  | 
You can control some procedural logic by using the YaTimeAPI.GetSecondsSinceStart method.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |  |