Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • The current FiberScope API is a prototype API to demonstrate and explore concepts. For now, FiberScope is an AutoCloseable and so encourages the use of the try-with-resources construct. The advantages of this approach is that it plays well with checked exceptions and it is easy to access variables in the enclosing scope. The downside is lack of guaranteed cleanup (a ThreadDeath, OOME, or other resource issues may abort the execution of the finally block and close). It is also possible to misuse, e.g. leak the scope to a callee that closes it explicitly. An alternative API that has also been prototyped

    Code Block
    languagejava
    FiberScope.cancellable(scope -> { ... });


    The downside with this approach is that checked exceptions are awkward to deal with. It also requires capturing of effectively final variables in the enclosing scope. The API surface is also larger as there are different consumer variants to allow for a return value (or none).
    We will re-evaluate this once we have more experience with the concepts.

  • At this things stand, the thread/exit exiting the scope does not automatically cancel fibers scheduled in the scope. This was prototyped, but prior to adding termination queues, and may need to looked at again. More use-cases are needed for this and other items.
  • The Python Trio library has automatic propagation of errors (to ensure that errors are never lost).  An approximate equivalent was prototyped with FiberScope so that a fiber terminating with an exception propagates the exception to the thread/fiber that scheduled it. With nesting, the exception might propagate up a tree. A concern with the approach is that it’s “too magic”. For now, the API requires an explicit join to obtain an exception thrown by a fiber.
  • At this time, a FiberScope object need to be guarded to avoid leaking to a callee that closes the scope. Another concern is the fibers method to obtain a stream of the fibers executing in the scope. The main use-cases for the fibers method is cancellation and debugging, both of these need to be re-examined.

...