- Loading...
...
In Project Loom, a prototype API has been developed called FiberScope that is a scope in which fibers are scheduled. Here is a basic example:
...
| Code Block | ||
|---|---|---|
| ||
try (var scope = FiberScope.cancellable()) { |
...
var fiber1 = scope.schedule(task); |
...
var fiber2 = scope.schedule(task); |
...
} |
A thread or fiber enters a scope by calling the FiberScope.cancellable method (we will explain cancellation later). It exits the scope when the code in the block completes and any fibers scheduled in the scope have terminated. The example schedules two fibers. The thread/fiber executing the above code may have to wait (in the FiberScope’s close method) until the two fibers have terminated.
...