How do I run tasks in Fibers once the Fiber.schedule methods are gone?

Arkadiusz Gasiński jigga at jigga.pl
Sat Jul 20 14:56:42 UTC 2019


Awesome, thanks!

Also, given these changes to Fiber's API, what would be the recommended way
to rewrite Mark's code <https://youtu.be/Csc2JRs6470?t=1598> he wrote for
his loom rest demo he did at Devoxx last year?

I assume that FiberScope.background().schedule() would be the simplest way
to refactor his ThreadPool.execute(Runnable) method, but perhaps
maintaining a dedicated FiberScope in the ThreadPool would be a better idea
(though FiberScope.isClosed() method would be useful to not schedule new
tasks if the scope has been closed)?

Thanks,
Arek

On Sat, Jul 20, 2019 at 4:17 PM Alan Bateman <Alan.Bateman at oracle.com>
wrote:

> On 20/07/2019 14:54, Arkadiusz Gasiński wrote:
> > Hi,
> >
> > As the subject line says, how shall I schedule a task to run in Fiber now
> > that the static Fiber.schedule methods are no longer available?
> All fibers are scheduled in a fiber scope. The javadoc has some examples
> that might help and I'm sure we'll expand those as the API progresses,
> e.g. get started with:
>
> try (var scope = FiberScope.open()) {
>      Fiber<String> fiber = scope.schedule(() -> "foo");
> }
>
> If you really want to schedule a fiber that outlives its parent then you
> can use FiberScope.background().schedule(...). The static schedule
> methods were just convenience methods for doing that but they didn't
> help with structured usage.
>
> -Alan
>
>


More information about the loom-dev mailing list