Skip to content

Commit

Permalink
(reactor) optimise schedule and next_tick
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen von Takach committed Nov 18, 2017
1 parent 1d4537b commit 142eb0a
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions lib/libuv/reactor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -475,31 +475,22 @@ def spawn(cmd, **args)

# Schedule some work to be processed on the event reactor as soon as possible (thread safe)
#
# @param callback [Proc] the callback to be called on the reactor thread
# @raise [ArgumentError] if block is not given
def schedule(callback = nil, &block)
callback ||= block
assert_block(callback)

# @yield the callback to be called on the reactor thread
def schedule
if reactor_thread?
callback.call
yield
else
@run_queue << callback
@run_queue << Proc.new
@process_queue.call
end

self
end

# Queue some work to be processed in the next iteration of the event reactor (thread safe)
#
# @param callback [Proc] the callback to be called on the reactor thread
# @raise [ArgumentError] if block is not given
def next_tick(callback = nil, &block)
callback ||= block
assert_block(callback)

@run_queue << callback
def next_tick(&block)
@run_queue << block
if reactor_thread?
# Create a next tick timer
if not @next_tick_scheduled
Expand Down

0 comments on commit 142eb0a

Please sign in to comment.