@yuneta/gobj-js 7.9.9 → 7.9.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5396,10 +5396,22 @@
5396
5396
  * c_timer.js
5397
5397
  *
5398
5398
  * GClass Timer
5399
- * High-level, feed timers from periodic time of yuno
5400
- * IN SECONDS! although the parameter is in milliseconds (msec)
5399
+ * High-level timer, fed by the browser's own timer service
5401
5400
  *
5402
- * Copyright (c) 2025, ArtGins.
5401
+ * Don't use gobj_start()/gobj_stop(), USE set_timeout..(), clear_timeout()
5402
+ *
5403
+ * The CONTRACT is the C one (see c_timer.h), and it is the whole
5404
+ * public surface: set_timeout() arms, clear_timeout() disarms, and
5405
+ * a one-shot is done once it fires. Whether the gobj is running is
5406
+ * an INTERNAL matter of this gclass -- nobody asking for a timeout
5407
+ * has to know it exists, and no caller should have to pair a
5408
+ * set_timeout() with a gobj_start() to make it work.
5409
+ *
5410
+ * What feeds the timer is the only thing that differs from C, and
5411
+ * it is deliberately invisible from outside: there the gobj rides
5412
+ * the yuno's one-second heartbeat, here it is a native setTimeout().
5413
+ *
5414
+ * Copyright (c) 2025-2026, ArtGins.
5403
5415
  * All Rights Reserved.
5404
5416
  ****************************************************************************/
5405
5417
  /***************************************************************
@@ -5452,6 +5464,9 @@
5452
5464
  if (priv.msec > 0) priv.timer_id = setTimeout(function() {
5453
5465
  gobj_send_event(gobj, "EV_TIMEOUT", {}, gobj);
5454
5466
  }, priv.msec);
5467
+ if (priv.msec > 0) {
5468
+ if (!gobj_is_running(gobj)) gobj_start(gobj);
5469
+ } else if (gobj_is_running(gobj)) gobj_stop(gobj);
5455
5470
  break;
5456
5471
  }
5457
5472
  }
@@ -5481,11 +5496,15 @@
5481
5496
  function ac_timeout$1(gobj, event, kw, src) {
5482
5497
  let priv = gobj.priv;
5483
5498
  let ev = priv.periodic ? "EV_TIMEOUT_PERIODIC" : "EV_TIMEOUT";
5484
- if (gobj_is_pure_child(gobj)) gobj_send_event(gobj_parent(gobj), ev, {}, gobj);
5485
- else gobj_publish_event(gobj, ev, {});
5486
- if (priv.periodic) priv.timer_id = setTimeout(function() {
5499
+ if (priv.periodic && priv.msec > 0) priv.timer_id = setTimeout(function() {
5487
5500
  gobj_send_event(gobj, "EV_TIMEOUT", {}, gobj);
5488
5501
  }, priv.msec);
5502
+ else priv.timer_id = -1;
5503
+ if (gobj_is_pure_child(gobj)) gobj_send_event(gobj_parent(gobj), ev, {}, gobj);
5504
+ else gobj_publish_event(gobj, ev, {});
5505
+ if (!priv.periodic && priv.timer_id === -1) {
5506
+ if (gobj_is_running(gobj)) gobj_stop(gobj);
5507
+ }
5489
5508
  return 0;
5490
5509
  }
5491
5510
  /***************************