欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

一小段代码理解Fiber 博客分类: RubyFiber rubyfiber 

程序员文章站 2024-02-12 15:12:34
...
server = Fiber.new do |request|
  puts 'Server Started'
  while(request != 'exit')
    puts "Received request: #{request}"
    request = Fiber.yield Random.rand
  end
end

response = server.resume 'hi'
puts response
response = server.resume 'hello'
puts response
response = server.resume 'exit'
puts response
server.resume '???'
相关标签: ruby fiber