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