Slide 51
Slide 51 text
付録 Fiber Schedulerのサンプル
51
Fiber.new do |io|
message = io.read_nonblock 5000
@selector.register Fiber.current, io
Fiber.yield
io.write_nonblock "response"
@selector.register Fiber.current, io
Fiber.yield
end
class Scheduler
def io_wait(io, events, timeout)
@selector.register Fiber.current, io, events
end
end
Fiber.set_scheduler(Scheduler.new)
Fiber. schedule do
message = io.read 5000
io.write "response"
end