Hello everyone. I'm looking to learn and understand more about Promises and working within Promesa. While the docs themselves give a set of basic workflows I'm looking for a bit deeper understanding of how one should and could work with the promises and other features within the library. With that in mind, does anyone have materials they'd like to share that allows to understand the entire promise topic a bit better? At the moment i'm looking to build understanding about the following topics and promesa in the context of JVM (clj) : • Logging from Promesa threads if an uncaught exception happens • The implementation and use-cases of Cancel within Promesa or: what does a feature complete implementation from a deferred task that can timeout look like? • Interaction of how promises interact with threads and virtual threads, if at all. If you could point me to materials related to the topic, I would greatly appreciate it. I've got a functional piece of code now with promises but it is not fully feature complete yet. Thanks and hope you have a good day.
On the JVM side, a promesa is just a CompletableFuture instance, and has nothing related to threads as is. I mean promesa can be crearted and resolved in the same thread.
Promesa/CompletableFuture is just syncrhonized wrapper on a value, that can be (but not mandatory) available on a future (in time). And exposes API for compose computations around the future available value.
The relation with threads is only related on what thread is resolved, so you can control how different composed computations (functions that chained using fmap, or mcat) are executed and where they are executed.
CompletableFutures plays very well with virtual threads because, blocking on a promise/CompletableFuture with @ or deref parks virtual thread gracefully. So they can be used as just a syncrhonization point.
Per example: on our code, all http request are dispatched to virtual threads, but some requests need to perform some syncrhonos not vthread friendly code, so we dispatch that code to an executor, and block the vthread waiting for a promise. Obviously this does not uses all the potential of the completablefuture composition API, but is ok for us. We just use it as Future instance. Take in account that CompletableFuture API was defined much before vthreads and they offer api for compose asyncrhonous operations. With vthreads all that composition is not really necessary, because you can just block waiting a result.
https://concurrencydeepdives.com/guide-completable-future/ looks very good introduction on completableFuture, but all warnings about sync operations are not valid for vthreads