Fiber API questions

Alan Bateman Alan.Bateman at
Mon Oct 29 08:29:15 UTC 2018

On 27/10/2018 16:59, Fabio Tudone wrote:
> Hi, I have some questions about the current "Fiber" API:
> - Why the constructors accepts only a "Runnable" and not a "Callable"?
> - Why on the other hand the static "Fiber#schedule" method doesn't return a
> "Fiber" but rather a "CompletableFuture"?
> This allows "Fiber" to avoid being generic (is there a specific reason for
> that BTW?) but it forces the user to choose between getting back a "Fiber"
> reference and being able to throw checked exceptions in the fiber code.
The Fibers API is currently very minimal and will likely to go through 
many iterations over the coming months. Yes, you can create a Fiber to 
execute a task expressed as a Runnable. There is no result to return 
through the API, instead it will communicate via a channel or other 
means. You are right that checked exceptions may be awkward but changing 
it to Callable and forcing return null is awkward too. I haven't seen 
calls for a functional interface between Runnable and Callable that 
returns void and throws Exception and I hope we can avoid that. When we 
get to structured concurrency there is potential to propagate exceptions 
to whoever scheduled the fiber so we potentially get into the checked 
vs. runtime exceptions issues then. The static schedule methods are for 
creating/scheduling fibers that execute a task that yield a result. I 
can't tell if you are looking for it to return the more general 
Future<V> instead CompletableFuture<V> or expecting Fiber to implement 
Future. In any case, you shouldn't need a reference to the Fiber object 
in this case.


More information about the loom-dev mailing list