0

而不是这样做,

@fiber = Fiber.new do
  # ...
end

我正在尝试做这样的事情:

def test
  yield
  # ...
end

def create(process)
  @fiber = Fiber.new(process)
end

create(method(:test))

如何使Fiber代码看起来像已完成的部分?

4

1 回答 1

4

只需将方法转换为块:

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
于 2018-06-06T08:00:18.037 回答