lowloop 0.8.20 → 0.8.21

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: 18b2f0ae67dc62083d5d2f241ff7ef4ce1d9b559e43c7e2ea501dc9374ce2348
4
- data.tar.gz: 4541c743b8ceb475f5741fbea328afb87fb4e517700e8b6364974f2c6c346d3a
3
+ metadata.gz: 8e074495089aa24b296af09830d3cbaf66544569591a681d43f10d2ca87144e6
4
+ data.tar.gz: 047246a6cf59057f058dd6db23faf934840164811d6ff8f7e67fdfdcacab26d5
5
5
  SHA512:
6
- metadata.gz: 2c6c514cebe4cee697089fd971d30fa28e65ddb03f4ba4b2bd719d556d103366c69f777b0a5db3ed74564ac92a2a11bea26c4bdf8e064223463c97c7c297433c
7
- data.tar.gz: ad5cc40e75412e724eb131be6449dca588da2b4e2e17fdf44e26aea8d1523e0fe4ce826256e173fe84217dc53324c87fcb5882d78b38644046d16d57c2f4e8fe
6
+ metadata.gz: e8743afc5bf62e3de5f6b41e0f3d94e6e273410871214d5a08f85a66d1e78ef0ee962835647cefdfc5760f3d07d6eea50da6246e5d0ad0e641c8d918bbe99736
7
+ data.tar.gz: 29d7c9d5e5a93c8ef3d466531db8e5b4bb6971e0d66fd963a2f76c26af2daa905e6c240fe4c26529f089f8b72f0038e4676c223824718c09e1daf4b9b8576aa7
@@ -11,8 +11,11 @@ module Low
11
11
  #
12
12
  # Interval[every_second: 30]
13
13
  # Interval[every_minute: 3, at_hour: 2]
14
+ #
15
+ # A tick that finds nothing to do can return Interval::IDLE, so its turn shows as idle rather than ran.
14
16
  class Interval < Low::Event
15
17
  UNITS = { every_second: 1, every_minute: 60, every_hour: 3600, every_day: 86_400 }.freeze
18
+ IDLE = :idle
16
19
  # Enough recent turns' outcomes for a dial of up to 60 marks like each second of a minute.
17
20
  KEPT_OUTCOMES = 64
18
21
 
@@ -62,23 +65,22 @@ module Low
62
65
  turn_at(now) > @turn
63
66
  end
64
67
 
65
- # Triggers its observers, marking the turn it's in as run and noting whether it ran or failed.
68
+ # Triggers its observers one after another, marking the turn it's in as run and noting how each one's went: ran,
69
+ # idle when it returned IDLE, or failed, which stops the rest.
66
70
  def tick(now = Time.now)
67
71
  @triggered_at = now
68
72
  @turn = turn_at(now)
69
- note_outcome(:running)
70
- trigger
71
- note_outcome(:ran)
72
- rescue StandardError
73
- note_outcome(:failed)
74
- raise
73
+ @outcomes[@turn] = {}
74
+ @outcomes.shift while @outcomes.size > KEPT_OUTCOMES
75
+ run_in_tree { Observers::Keys[@key].observers.each { |observer| tick_observer(observer) } }
75
76
  end
76
77
 
77
- # What happened on the turn under way at that time: running or ran or failed. It's skipped when the turn passed
78
- # without running since the app started and nil for a turn still to come or from before.
79
- def outcome_at(time, now: Time.now)
78
+ # What happened to an observer, by its object, on the turn under way at that time: running, ran, idle or failed.
79
+ # It's skipped when the turn passed without running since the app started, and nil for a turn still to come, from
80
+ # before, or that stopped before it.
81
+ def outcome_at(time, object, now: Time.now)
80
82
  turn = turn_at(time)
81
- return @outcomes[turn] if @outcomes.key?(turn)
83
+ return @outcomes[turn][object] if @outcomes.key?(turn)
82
84
  return unless @first_turn && turn > @first_turn && turn < turn_at(now)
83
85
 
84
86
  :skipped
@@ -96,9 +98,13 @@ module Low
96
98
 
97
99
  private
98
100
 
99
- def note_outcome(outcome)
100
- @outcomes[@turn] = outcome
101
- @outcomes.shift while @outcomes.size > KEPT_OUTCOMES
101
+ def tick_observer(observer)
102
+ @outcomes[@turn][observer.object] = :running
103
+ result = observer.trigger(action: :tick, event: self)
104
+ @outcomes[@turn][observer.object] = result == IDLE ? :idle : :ran
105
+ rescue StandardError
106
+ @outcomes[@turn][observer.object] = :failed
107
+ raise
102
108
  end
103
109
 
104
110
  # How many turns have passed since the epoch on the server's clock.
data/lib/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Low
4
4
  module Loop
5
- VERSION = '0.8.20'
5
+ VERSION = '0.8.21'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lowloop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.20
4
+ version: 0.8.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - maedi