Skip to content

Commit 44d514d

Browse files
committed
fix(scheduler): improve stability
and simplify type system
1 parent d13dc21 commit 44d514d

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

shard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: placeos-driver
2-
version: 7.15.0
2+
version: 7.16.0
33

44
dependencies:
55
action-controller:

spec/scheduler_spec.cr

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ describe PlaceOS::Driver::Proxy::Scheduler do
3232
sched.size.should eq(0)
3333
end
3434

35-
it "should be possible to obtain the return value of the task" do
35+
it "should be possible to wait for a task to complete" do
3636
sched = PlaceOS::Driver::Proxy::Scheduler.new
3737

3838
# Test execution
3939
task = sched.at(2.milliseconds.from_now) { true }
40-
task.get.should eq true
40+
task.get.should eq nil
4141

4242
# Test failure
4343
task = sched.at(2.milliseconds.from_now) { raise "was error" }
@@ -138,7 +138,7 @@ describe PlaceOS::Driver::Proxy::Scheduler do
138138
task.cancel
139139
end
140140

141-
it "should be possible to obtain the next value of a repeating" do
141+
it "should be possible to step through a repeating task" do
142142
sched = PlaceOS::Driver::Proxy::Scheduler.new
143143
ran = 0
144144
task = sched.every(2.milliseconds) do
@@ -148,14 +148,18 @@ describe PlaceOS::Driver::Proxy::Scheduler do
148148
end
149149

150150
# Test execution
151-
task.get.should eq 1
152-
task.get.should eq 2
153-
task.get.should eq 3
151+
task.get
152+
ran.should eq 1
153+
task.get
154+
ran.should eq 2
155+
task.get
156+
ran.should eq 3
154157
expect_raises(Exception, "some error") do
155-
task.get.should eq 4
158+
task.get
156159
raise "failed"
157160
end
158-
task.get.should eq 5
161+
task.get
162+
ran.should eq 5
159163

160164
# Test cancelation
161165
spawn(same_thread: true) { task.cancel }

src/placeos-driver/proxy/scheduler.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class PlaceOS::Driver::Proxy::Scheduler
9494
schedules.each &.cancel(terminate: @terminated)
9595
end
9696

97-
private def run_now(block)
97+
private def run_now(block) : Nil
9898
block.call
9999
rescue error
100100
logger.error(exception: error) { "in scheduled task on #{DriverManager.driver_class}" }

0 commit comments

Comments
 (0)