timer.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. // The entry file of your WebAssembly module.
  6. import * as console from '../wamr_app_lib/console'
  7. import * as timer from '../wamr_app_lib/timer'
  8. /* clousure is not implemented yet, we need to declare global variables
  9. so that they can be accessed inside a callback function */
  10. var cnt = 0;
  11. var my_timer: timer.user_timer;
  12. export function on_init(): void {
  13. /* The callback function will be called every 2 second,
  14. and will stop after 10 calls */
  15. my_timer = timer.setInterval(() => {
  16. cnt ++;
  17. console.log((cnt * 2).toString() + " seconds passed");
  18. if (cnt >= 10) {
  19. timer.timer_cancel(my_timer);
  20. console.log("Stop Timer");
  21. }
  22. }, 2000);
  23. }
  24. export function on_destroy(): void {
  25. }
  26. /* Function below are requred by wamr runtime, don't remove or modify them */
  27. export function _on_timer_callback(on_timer_id: i32): void {
  28. timer.on_timer_callback(on_timer_id);
  29. }