You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Always requires the latest Loom build from [https://jdk.java.net/21/](https://jdk.java.net/21/)
16
-
17
-
*Note that Loom is in early access and the API, naming and usage keeps changing, a lot.*
16
+
Requires a JDK that has Virtual Threads as standard feature (i.e., not preview), such as [https://jdk.java.net/21/](https://jdk.java.net/21/).
18
17
19
18
# Components
20
19
21
20
## FiberInterop
22
21
22
+
### Schedulers
23
+
24
+
Currently, the Virtual Thread API does not offer public means to specify the carrier thread(pool) thus it is not possible to use RxJava `Scheduler`s as such.
25
+
26
+
You can use the `Schedulers.from` though to convert the Fork-Join-pool backed standard Virtual Thread Executor into an RxJava `Scheduler`:
27
+
28
+
```java
29
+
var vte =Executors.newVirtualThreadExecutor();
30
+
Scheduler vtScheduler =Schedulers.from(vte);
31
+
32
+
// sometime later
33
+
vte.close();
34
+
```
35
+
36
+
You can then use `vtScheduler` from the example with `subscribeOn` and `observeOn` to let traditional functional callbacks to block virtually:
.subscribe(v -> label.setText(v), e -> label.setText(e.toString()));
45
+
```
46
+
47
+
:information_source: You need the special operators below to make RxJava's non-blocking backpressure into virtually blocked backpressure.
48
+
23
49
### create
24
50
25
51
Creates a `Flowable` from a generator callback, that can emit via `FiberEmitter`, run on an `ExecutorService` provided by the user and
26
-
is suspended automatically upon backpressure.
27
-
28
-
:warning: Since version 0.0.15 of this library and with the current latest Loom preview 18b5, there is no public way to
29
-
specify a carrier thread beneath a virtual thread executor anymore. Therefore, the single-argument and `Scheduler`-argumented overloads
30
-
of `create` have been removed.
52
+
is suspended automatically upon backpressure. The callback is executed inside the virtual thread thus you can call the usual blocking APIs and get suspensions the same way.
31
53
32
54
The created `Flowable` will complete once the callback returns normally or with an error if the callback throws an exception.
Transforms each upstream value via a callback that can emit zero or more values for each of those upstream values, run on an `ExecutorService` provided by the user and
50
-
is suspended automatically upon backpressure.
51
-
52
-
:warning: Since version 0.0.15 of this library and with the current latest Loom preview 18b5, there is no public way to
53
-
specify a carrier thread beneath a virtual thread executor anymore. Therefore, the single-argument and `Scheduler`-argumented overloads
54
-
of `create` have been removed.
71
+
Transforms each upstream value via a callback that can emit zero or more values for each of those upstream values, run on an `ExecutorService` provided by the user and is suspended automatically upon backpressure. The callback is executed inside the virtual thread thus you can call the usual blocking APIs and get suspensions the same way.
RxJava uses `java.util.concurrent` locks and `CountDownLatches` via its `blockingXXX` which will automatically work within a virtual thread. Therefore, there is no need for a separate interop operator. Just block.
0 commit comments