diff --git a/lib/libuv/pipe.rb b/lib/libuv/pipe.rb index 6c4cfbb..c7ecf6f 100644 --- a/lib/libuv/pipe.rb +++ b/lib/libuv/pipe.rb @@ -59,7 +59,7 @@ def open(fileno) self end - def connect(name) + def connect(name, &block) return if @closed assert_type(String, name, "name must be a String") @@ -72,7 +72,7 @@ def connect(name) end if block_given? - @callback = Proc.new + @callback = block else @coroutine = @reactor.defer @coroutine.promise.value diff --git a/lib/libuv/q.rb b/lib/libuv/q.rb index 043d9e0..67f124b 100644 --- a/lib/libuv/q.rb +++ b/lib/libuv/q.rb @@ -104,9 +104,9 @@ def initialize(reactor, defer) # # @param [Proc, Proc, Proc, &blk] callbacks error, success, progress, success_block # @return [Promise] Returns an unresolved promise for chaining - def then(callback = nil, errback = nil, progback = nil) + def then(callback = nil, errback = nil, progback = nil, &block) result = Q.defer(@reactor) - callback = Proc.new if block_given? + callback = block if block_given? wrappedCallback = proc { |val| begin @@ -182,9 +182,9 @@ def initialize(reactor, response, error = false) @response = response end - def then(callback = nil, errback = nil, progback = nil) + def then(callback = nil, errback = nil, progback = nil, &block) result = Q.defer(@reactor) - callback = Proc.new if block_given? + callback = block if block_given? @reactor.next_tick { if @error diff --git a/lib/libuv/reactor.rb b/lib/libuv/reactor.rb index bdc40e0..b81e78b 100644 --- a/lib/libuv/reactor.rb +++ b/lib/libuv/reactor.rb @@ -236,9 +236,9 @@ def active_handles # Provides a promise notifier for receiving un-handled exceptions # # @return [::Libuv::Q::Promise] - def notifier + def notifier(&block) @reactor_notify = if block_given? - Proc.new + block else @reactor_notify_default end @@ -505,11 +505,11 @@ def spawn(cmd, **args) # Schedule some work to be processed on the event reactor as soon as possible (thread safe) # # @yield the callback to be called on the reactor thread - def schedule + def schedule(&block) if reactor_thread? yield else - @run_queue << Proc.new + @run_queue << block @process_queue.call end self diff --git a/lib/libuv/tcp.rb b/lib/libuv/tcp.rb index 7a8c76a..646e58f 100644 --- a/lib/libuv/tcp.rb +++ b/lib/libuv/tcp.rb @@ -249,14 +249,14 @@ def bind(ip, port, **tls_options, &blk) self end - def open(fd, binding = true) + def open(fd, binding = true, &block) return self if @closed if binding @on_listen = proc { accept } - @on_accept = Proc.new + @on_accept = block elsif block_given? - @callback = Proc.new + @callback = block else @coroutine = @reactor.defer end @@ -267,7 +267,7 @@ def open(fd, binding = true) self end - def connect(ip, port) + def connect(ip, port, &block) return self if @closed assert_type(String, ip, IP_ARGUMENT_ERROR) @@ -281,7 +281,7 @@ def connect(ip, port) end if block_given? - @callback = Proc.new + @callback = block else @coroutine = @reactor.defer @coroutine.promise.value