Skip to content

Commit 5e5d84a

Browse files
committed
Fix callback example.
1 parent 809025c commit 5e5d84a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

examples/callback/loop.rb

100644100755
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env ruby
2+
13
# frozen_string_literal: true
24

35
require 'async/reactor'
@@ -12,14 +14,12 @@ def close
1214
end
1315

1416
# If duration is 0, it will happen immediately after the task is started.
15-
def run(duration = 0)
16-
@reactor.run do |task|
17-
@reactor.after(duration) do
18-
@reactor.stop
19-
end
20-
21-
yield(task) if block_given?
17+
def run(duration = 0, &block)
18+
if block_given?
19+
@reactor.async(&block)
2220
end
21+
22+
@reactor.run_once(duration)
2323
end
2424
end
2525

0 commit comments

Comments
 (0)