如何使用 'method' 而不是代码块创建纤程
How to create a fiber using 'method' instead of a code block
而不是这样做,
@fiber = Fiber.new do
# ...
end
我正在尝试做这样的事情:
def test
yield
# ...
end
def create(process)
@fiber = Fiber.new(process)
end
create(method(:test))
如何使 Fiber
代码看起来像完成的部分?
只需将方法转换为块:
def test
Fiber.yield 2.71
Fiber.yield 3.14
Fiber.yield 42
end
def create(&process)
@fiber = Fiber.new(&process)
end
create(&method(:test))
@fiber.resume # => 2.71
@fiber.resume # => 3.14
@fiber.resume # => 42
而不是这样做,
@fiber = Fiber.new do
# ...
end
我正在尝试做这样的事情:
def test
yield
# ...
end
def create(process)
@fiber = Fiber.new(process)
end
create(method(:test))
如何使 Fiber
代码看起来像完成的部分?
只需将方法转换为块:
def test
Fiber.yield 2.71
Fiber.yield 3.14
Fiber.yield 42
end
def create(&process)
@fiber = Fiber.new(&process)
end
create(&method(:test))
@fiber.resume # => 2.71
@fiber.resume # => 3.14
@fiber.resume # => 42