@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.
@@ -5394,10 +5394,22 @@ var gobjJs = (function(exports) {
5394
5394
  * c_timer.js
5395
5395
  *
5396
5396
  * GClass Timer
5397
- * High-level, feed timers from periodic time of yuno
5398
- * IN SECONDS! although the parameter is in milliseconds (msec)
5397
+ * High-level timer, fed by the browser's own timer service
5399
5398
  *
5400
- * Copyright (c) 2025, ArtGins.
5399
+ * Don't use gobj_start()/gobj_stop(), USE set_timeout..(), clear_timeout()
5400
+ *
5401
+ * The CONTRACT is the C one (see c_timer.h), and it is the whole
5402
+ * public surface: set_timeout() arms, clear_timeout() disarms, and
5403
+ * a one-shot is done once it fires. Whether the gobj is running is
5404
+ * an INTERNAL matter of this gclass -- nobody asking for a timeout
5405
+ * has to know it exists, and no caller should have to pair a
5406
+ * set_timeout() with a gobj_start() to make it work.
5407
+ *
5408
+ * What feeds the timer is the only thing that differs from C, and
5409
+ * it is deliberately invisible from outside: there the gobj rides
5410
+ * the yuno's one-second heartbeat, here it is a native setTimeout().
5411
+ *
5412
+ * Copyright (c) 2025-2026, ArtGins.
5401
5413
  * All Rights Reserved.
5402
5414
  ****************************************************************************/
5403
5415
  /***************************************************************
@@ -5450,6 +5462,9 @@ var gobjJs = (function(exports) {
5450
5462
  if (priv.msec > 0) priv.timer_id = setTimeout(function() {
5451
5463
  gobj_send_event(gobj, "EV_TIMEOUT", {}, gobj);
5452
5464
  }, priv.msec);
5465
+ if (priv.msec > 0) {
5466
+ if (!gobj_is_running(gobj)) gobj_start(gobj);
5467
+ } else if (gobj_is_running(gobj)) gobj_stop(gobj);
5453
5468
  break;
5454
5469
  }
5455
5470
  }
@@ -5479,11 +5494,15 @@ var gobjJs = (function(exports) {
5479
5494
  function ac_timeout$1(gobj, event, kw, src) {
5480
5495
  let priv = gobj.priv;
5481
5496
  let ev = priv.periodic ? "EV_TIMEOUT_PERIODIC" : "EV_TIMEOUT";
5482
- if (gobj_is_pure_child(gobj)) gobj_send_event(gobj_parent(gobj), ev, {}, gobj);
5483
- else gobj_publish_event(gobj, ev, {});
5484
- if (priv.periodic) priv.timer_id = setTimeout(function() {
5497
+ if (priv.periodic && priv.msec > 0) priv.timer_id = setTimeout(function() {
5485
5498
  gobj_send_event(gobj, "EV_TIMEOUT", {}, gobj);
5486
5499
  }, priv.msec);
5500
+ else priv.timer_id = -1;
5501
+ if (gobj_is_pure_child(gobj)) gobj_send_event(gobj_parent(gobj), ev, {}, gobj);
5502
+ else gobj_publish_event(gobj, ev, {});
5503
+ if (!priv.periodic && priv.timer_id === -1) {
5504
+ if (gobj_is_running(gobj)) gobj_stop(gobj);
5505
+ }
5487
5506
  return 0;
5488
5507
  }
5489
5508
  /***************************