Skip to content

Commit

Permalink
fix syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach committed Mar 1, 2024
1 parent d5b2e15 commit 6c1f060
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/libuv/pipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -72,7 +72,7 @@ def connect(name)
end

if block_given?
@callback = Proc.new
@callback = block
else
@coroutine = @reactor.defer
@coroutine.promise.value
Expand Down
8 changes: 4 additions & 4 deletions lib/libuv/q.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/libuv/reactor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/libuv/tcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -281,7 +281,7 @@ def connect(ip, port)
end

if block_given?
@callback = Proc.new
@callback = block
else
@coroutine = @reactor.defer
@coroutine.promise.value
Expand Down

0 comments on commit 6c1f060

Please sign in to comment.