@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.
@@ -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
  /***************************
@@ -5636,7 +5655,6 @@ var gobjJs = (function(exports) {
5636
5655
  * Framework Method: Start
5637
5656
  ***************************************************************/
5638
5657
  function mt_start$1(gobj) {
5639
- gobj_start(gobj.priv.gobj_timer);
5640
5658
  set_timeout_periodic(gobj.priv.gobj_timer, gobj.priv.periodic_timeout);
5641
5659
  return 0;
5642
5660
  }
@@ -5644,7 +5662,7 @@ var gobjJs = (function(exports) {
5644
5662
  * Framework Method: Stop
5645
5663
  ***************************************************************/
5646
5664
  function mt_stop$1(gobj) {
5647
- gobj_stop(gobj.priv.gobj_timer);
5665
+ clear_timeout(gobj.priv.gobj_timer);
5648
5666
  gobj_stop_children(gobj);
5649
5667
  return 0;
5650
5668
  }
@@ -5816,7 +5834,6 @@ var gobjJs = (function(exports) {
5816
5834
  ***************************************************************/
5817
5835
  function mt_start(gobj) {
5818
5836
  let priv = gobj.priv;
5819
- gobj_start(priv.gobj_timer);
5820
5837
  priv.retry_ms = 0;
5821
5838
  priv.websocket = setup_websocket(gobj);
5822
5839
  return 0;
@@ -5827,7 +5844,6 @@ var gobjJs = (function(exports) {
5827
5844
  function mt_stop(gobj) {
5828
5845
  let priv = gobj.priv;
5829
5846
  clear_timeout(priv.gobj_timer);
5830
- gobj_stop(priv.gobj_timer);
5831
5847
  if (priv.websocket) close_websocket(gobj);
5832
5848
  return 0;
5833
5849
  }