How to terminate a continuation early and call `finally` blocks?

Remi Forax forax at univ-mlv.fr
Tue Sep 8 13:19:37 UTC 2020


I believe that Generator.return() is equivalent to CompletableFuture.complete(value).
So creating a CompletableFuture on an Executors.newVirtualThreadExecutor() will get you the semantics you want if you don't need an explicit yield which as Ron said if currently out of scope.

Rémi

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return

----- Mail original -----
> De: "Ron Pressler" <ron.pressler at oracle.com>
> À: "Михаил Кузьмин" <m.kuzmin at darkleaf.ru>, "loom-dev" <loom-dev at openjdk.java.net>
> Envoyé: Mardi 8 Septembre 2020 14:39:16
> Objet: Re: How to terminate a continuation early and call `finally` blocks?

> Loom’s continuation are a capability that’s used internally by the
> JDK to implement virtual threads.
> 
> Whether or not the JDK will one day also use that mechanism to implement
> other constructs, like generators, is beyond our scope at this time.
> 
> — Ron
> 
> 
> 
> On 8 September 2020 at 13:35:04, Михаил Кузьмин
> (m.kuzmin at darkleaf.ru(mailto:m.kuzmin at darkleaf.ru)) wrote:
> 
>> JS generators have the `return` method:
>>  
>> ```javascript
>> var fn_gen = function* () {
>> try {
>> yield
>> }
>> finally {
>> console.log("finally")
>> }
>> };
>>  
>> var gen = fn_gen();
>> gen.next()
>> // => {value: undefined, done: false}
>> gen.return()
>> // => finally <= the finally block has been executed
>> // => {value: undefined, done: true}
>> ```
>>  
>> Will it be possible with Loom's continuations?


More information about the loom-dev mailing list