Strand class & continuation example

Arkadiusz Gasiński jigga at jigga.pl
Wed Jan 30 18:11:50 UTC 2019


Hi,

I assume that you're all busy with the loom project, but if anyone here
finds some time to briefly explain the rationale behind removal of the
Strand class, I'll be really grateful.

I tried to find some explanation in the mailing list archive, but to no
avail.

Also, if you could provide some very basic example of Continuation usage
without involving Fibers as I'm struggling with the below code (perhaps I
got the whole idea wrong):

var scope = new ContinuationScope("main");

Continuation cont = new Continuation(scope, () -> {
   while (true) {
      // do very important stuff
   }
});
cont.run();

while (!cont.isDone()) {
   // try yield the continuation
   Continuation.yield(scope);
   // sleep some
   try {
      TimeUnit.SECONDS.sleep(3);
   } catch (InterruptedException e) {
      // ignore
   } finally {
      cont.run();
   }
}

As you probably guess by now, I can't get past the first cont.run() call as
it block main. If I run the continuation for the first time in a separate
thread, then Continuation.yield(scope) throws IllegalArgumentException("Not
in scope " + scope).

So basically what I'd like to achieve is to run some continuation, yield it
after a while and then resume it from where it was before yielding, if of
course, this is possible.

Thanks,
Arek


More information about the loom-dev mailing list