psched 0.1.0 → 0.1.1

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/psched.rb +12 -7
  3. data/lib/psched/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58946f4a0c8a49837d18022f99a4f98c99cf3117
4
- data.tar.gz: c1d675d5dba069199d49420407694171855261e1
3
+ metadata.gz: 2618d52912d1a08593f44940d90bbbb503f48219
4
+ data.tar.gz: b2a5e8b33db59636e8e2127fa0d7794daca3e18b
5
5
  SHA512:
6
- metadata.gz: 47cbf71e0f1f5c47c58980105761bfd0d65dd68a3d9b1fe39f5b54efbbe4ec7e72b10d897e9151bcee797c24319653b916b1a8de07591ac0d8473cb9f2e7c103
7
- data.tar.gz: a0e0a9d007693cda71f86ae85b8c6280f4fc873fa2f4288520e9382d25eaae0682b532dda4c77a1dbf58824d2b009bceb1d76c3f680172bb56e73fada7b62d69
6
+ metadata.gz: 7f39ada8cf3c15e5cdfc8bdc35369f445e3f23b6bbe598fe8e08938b04d59acf6f72c9e305ad41d928ab682e16aebeb6e987ce0a4d06453868be4cf9a2da8b6a
7
+ data.tar.gz: 5a697c532f4ad04f0aa1004b590b1aabdc0aac1d1bc3d200072e8cf37c0680c7ec12cb8fde5d7c7967f78207fc23319158d4c628134eb5b732448e8402a8cd95
data/lib/psched.rb CHANGED
@@ -88,7 +88,10 @@ module PSched
88
88
  # The Task Execution Time
89
89
  # @!attribute [r] step
90
90
  # The time step in seconds
91
- attr_reader :step, :tet
91
+ # @!attribute [r] start_time
92
+ # The time at the beginning of the current Operation
93
+ attr_reader :step, :tet, :start_time
94
+
92
95
  # Initializer
93
96
  # @param [Numeric] step the timestep in seconds
94
97
  def initialize(step)
@@ -124,13 +127,15 @@ module PSched
124
127
  # @param [Fixnum,nil] n_iter the maximum number of iterations.
125
128
  # If nil it loops indefinitedly
126
129
  # @yieldparam [Fixnum] i the number of elapsed iterations
127
- # @yieldparam [Numeric] tet the Task Execution Time of previous step
130
+ # @yieldparam [Float] t the time elapsed since the beginning of current Operation
131
+ # @yieldparam [Float] tet the Task Execution Time of previous step
128
132
  # @raise [ArgumentError] unless a block is given
129
133
  # @raise [RealTimeError] if TET exceeds @step
130
134
  def start(n_iter=nil)
135
+ raise ArgumentError, "Need a block!" unless block_given?
131
136
  @active = true
132
137
  i = 0
133
- raise ArgumentError, "Need a block!" unless block_given?
138
+ @start_time = Time.now
134
139
  Signal.trap(:ALRM) do
135
140
  # If there is still a pending step, raises an error containing
136
141
  # information about the CURRENT step
@@ -142,7 +147,7 @@ module PSched
142
147
  else
143
148
  start = Time.now
144
149
  @lock = true
145
- result = yield(i, @tet)
150
+ result = yield(i, Time.now - @start_time, @tet)
146
151
  i += 1
147
152
  self.stop if (n_iter and i >= n_iter)
148
153
  self.stop if (result.kind_of? Symbol and result == :stop)
@@ -177,9 +182,9 @@ end
177
182
  if $0 == __FILE__ then
178
183
  PSched::Operation.prioritize
179
184
 
180
- op = PSched::Operation.new(0.01)
181
- op.start(10) do |i|
182
- puts "Ping #{i}"
185
+ op = PSched::Operation.new(0.5)
186
+ op.start(10) do |i, t|
187
+ puts "Ping #{i}: #{t}"
183
188
  end
184
189
 
185
190
  Signal.trap("SIGINT") do
@@ -1,4 +1,4 @@
1
1
  module Psched
2
2
  # psched version
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: psched
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paolo Bosetti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-13 00:00:00.000000000 Z
11
+ date: 2017-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi