We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 809025c commit 5e5d84aCopy full SHA for 5e5d84a
examples/callback/loop.rb
100644
100755
@@ -1,3 +1,5 @@
1
+#!/usr/bin/env ruby
2
+
3
# frozen_string_literal: true
4
5
require 'async/reactor'
@@ -12,14 +14,12 @@ def close
12
14
end
13
15
16
# If duration is 0, it will happen immediately after the task is started.
- def run(duration = 0)
- @reactor.run do |task|
17
- @reactor.after(duration) do
18
- @reactor.stop
19
- end
20
-
21
- yield(task) if block_given?
+ def run(duration = 0, &block)
+ if block_given?
+ @reactor.async(&block)
22
+ @reactor.run_once(duration)
23
24
25
0 commit comments