Sha256: 345550e9ee9bbaad3a934b0af47b9d8d85b1717e3f521d10e8140d7e454c1c5f
Contents?: true
Size: 1.58 KB
Versions: 7
Compression:
Stored size: 1.58 KB
Contents
# # MessagePack-RPC for Ruby # # Copyright (C) 2010-2011 FURUHASHI Sadayuki # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # module MessagePack module RPC Loop = Cool.io::Loop module LoopUtil attr_reader :loop class Timer < Cool.io::TimerWatcher def initialize(interval, repeating, &block) @block = block super(interval, repeating) end def on_timer @block.call end end def start_timer(interval, repeating, &block) @loop.attach Timer.new(interval, repeating, &block) end class TaskQueue < Cool.io::AsyncWatcher def initialize @queue = [] super end def push(task) @queue.push(task) signal end def on_signal while task = @queue.shift begin task.call rescue end end end end def submit(task = nil, &block) task ||= block unless @queue @queue = TaskQueue.new @loop.attach(@queue) end @queue.push(task) end def run @loop.run end def stop @queue.detach if @queue && @queue.attached? @loop.stop # attach dummy timer @loop.attach Cool.io::TimerWatcher.new(0, false) nil end end end end
Version data entries
7 entries across 7 versions & 1 rubygems