behavior_machines 0.1.0 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec761ecd4fe6d6f47c9441607ef0df573a49ec611d96f113f46547e7872b219d
4
- data.tar.gz: 16be482a97faa6d3807aa41cc66d4e1088a1e0732f11ad12cfcb53e70e0fdc32
3
+ metadata.gz: 9a83e1e8b54ae643e0763d07afbf5b34f5ddf80790c55e57a958f82754a8328f
4
+ data.tar.gz: 4df17f639b4f87c83473508e5d44eac058f1e9ced1ebce87a630c0a27498818f
5
5
  SHA512:
6
- metadata.gz: 446b75ee20966a1564d2669645018c06dab4a2ce535ae2f57a6bdb070d1ec628e99dd29812ca32168103da2f9cbcefb46311557d3631b718844fe49b8a230d79
7
- data.tar.gz: 3a0e4f7c47e9b787c95d1ab4a2c9dbe71205f46bedc291153a698093affc6d5d874789187fba678b7595ae1efe05e020236c48131889d63210adfd77be506266
6
+ metadata.gz: c3bb6e3ba9b6f58c861193cdc944c425167544425531b60d06ea31c2a5d7b6bd3354101918f22d3593ae26cb27399058eedf9f668316fa22da1d0815006458a2
7
+ data.tar.gz: fe002a3c84e4dce7e8d8049762f062bcc31f39c17a52c4b02921d2a2e46d42bf6c40dab32d63cd0155fd8385b0e27033920d37181c27609ecf4ee63cc1d9846d
data/README.md CHANGED
@@ -68,7 +68,8 @@ compiles them.
68
68
  Durations are seconds. The clock is an Integer count of nanoseconds, passed as
69
69
  `now:` and defaulting to `BehaviorMachines.now` (monotonic).
70
70
  `tree.next_deadline` returns when a running `sleep` or `timeout` next needs a
71
- tick, so a host can sleep until then.
71
+ tick, so a host can sleep until then. A looping decorator that finished a run
72
+ reports that tick's time, so its next run is due at once.
72
73
 
73
74
  ## Errors
74
75
 
@@ -441,7 +441,7 @@ module BehaviorMachines
441
441
  end
442
442
 
443
443
  # Repeat, RetryUntilSuccessful, and KeepRunningUntilFailure: at most one
444
- # finished child run per tick.
444
+ # finished child run per tick; the next run is due at once.
445
445
  class LoopSlot < Slot
446
446
  def initialize(id, child, again_on, limit)
447
447
  super(id)
@@ -449,20 +449,28 @@ module BehaviorMachines
449
449
  @again_on = again_on
450
450
  @limit = limit
451
451
  @runs = 0
452
+ @due = nil
452
453
  end
453
454
 
454
455
  private
455
456
 
456
457
  def step(run, now, _starting)
458
+ @due = nil
457
459
  return @again_on if @limit&.zero?
458
460
 
459
461
  status = @child.tick(run, now)
460
462
  return status if status == :running
461
463
  return finish(status) unless status == @again_on
462
- return :running if @limit.nil?
464
+ return again(now) if @limit.nil?
463
465
  return finish(status) if @runs + 1 == @limit
464
466
 
465
467
  @runs += 1
468
+ again(now)
469
+ end
470
+
471
+ # A run finished and the next waits for a tick: due at once.
472
+ def again(now)
473
+ @due = now
466
474
  :running
467
475
  end
468
476
 
@@ -476,7 +484,7 @@ module BehaviorMachines
476
484
  @runs = 0
477
485
  end
478
486
 
479
- def running_deadline = @child.next_deadline
487
+ def running_deadline = earliest([@due, @child.next_deadline])
480
488
  end
481
489
  end
482
490
  end
@@ -53,7 +53,8 @@ module BehaviorMachines
53
53
  @engine.running?
54
54
  end
55
55
 
56
- # The earliest time, in nanoseconds, a running Sleep or Timeout will fire.
56
+ # The earliest time, in nanoseconds, a running Sleep or Timeout will fire,
57
+ # or a looping decorator wants its next run (already due).
57
58
  def next_deadline
58
59
  check_idle
59
60
  @engine.next_deadline
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BehaviorMachines
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: behavior_machines
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih