From 142eb0a17453440666b72a541bb48ec3361d2066 Mon Sep 17 00:00:00 2001 From: Stephen von Takach Date: Sun, 19 Nov 2017 01:29:04 +1100 Subject: [PATCH] (reactor) optimise schedule and next_tick --- lib/libuv/reactor.rb | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/lib/libuv/reactor.rb b/lib/libuv/reactor.rb index 8c78abc..4a032df 100644 --- a/lib/libuv/reactor.rb +++ b/lib/libuv/reactor.rb @@ -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