Sha256: eb5ccbd78821b782bdb2dd4fb75e7821ae28688f7ff5857bd4733c57b54b486b
Contents?: true
Size: 955 Bytes
Versions: 1
Compression:
Stored size: 955 Bytes
Contents
# IOloop like a per-threaded Eventmachine (cause fiber cannot resume cross threads) # join, 等待 IOloop 结束 # 在 loop 中为 waiter (future-like proxy object) 对象返回结果 module LightIO class IOloop def initialize @fiber = Fiber.new {run} @backend = Backend::NIO.new end # should never invoke explicitly def run # start io loop and never return... @backend.run end # wait a watcher, maybe a timer or socket def wait(watcher) future = Future.new # add watcher to loop watcher.set_callback {future.transfer} watcher.register(@backend) # trigger a fiber switch # wait until watcher is ok # then do work future.value end def transfer @fiber.transfer end class << self # return current ioloop or create new one def current Thread.current[:"lightio.ioloop"] ||= IOloop.new end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
lightio-0.1.0.pre | lib/lightio/ioloop.rb |