@yuneta/gobj-js 7.9.9 → 7.9.11

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
  /***************************
@@ -5638,7 +5657,6 @@
5638
5657
  * Framework Method: Start
5639
5658
  ***************************************************************/
5640
5659
  function mt_start$1(gobj) {
5641
- gobj_start(gobj.priv.gobj_timer);
5642
5660
  set_timeout_periodic(gobj.priv.gobj_timer, gobj.priv.periodic_timeout);
5643
5661
  return 0;
5644
5662
  }
@@ -5646,7 +5664,7 @@
5646
5664
  * Framework Method: Stop
5647
5665
  ***************************************************************/
5648
5666
  function mt_stop$1(gobj) {
5649
- gobj_stop(gobj.priv.gobj_timer);
5667
+ clear_timeout(gobj.priv.gobj_timer);
5650
5668
  gobj_stop_children(gobj);
5651
5669
  return 0;
5652
5670
  }
@@ -5818,7 +5836,6 @@
5818
5836
  ***************************************************************/
5819
5837
  function mt_start(gobj) {
5820
5838
  let priv = gobj.priv;
5821
- gobj_start(priv.gobj_timer);
5822
5839
  priv.retry_ms = 0;
5823
5840
  priv.websocket = setup_websocket(gobj);
5824
5841
  return 0;
@@ -5829,7 +5846,6 @@
5829
5846
  function mt_stop(gobj) {
5830
5847
  let priv = gobj.priv;
5831
5848
  clear_timeout(priv.gobj_timer);
5832
- gobj_stop(priv.gobj_timer);
5833
5849
  if (priv.websocket) close_websocket(gobj);
5834
5850
  return 0;
5835
5851
  }