thunkware / virtual-threads-bridge

Use Java21's Virtual Threads API in Java 8+
MIT License
8 stars 3 forks source link

Add an option to configure a timeout for the SemaphoreExecutor #21

Closed JordiMartinezVicent closed 3 months ago

JordiMartinezVicent commented 4 months ago

Currently the SemaphoreExecutor internally uses the Sempahore method acquire . It blocks the operation until one permits is available. It is nice as VirtualThreads behavior is something similar but there are occasions that is preferable to fail-fast.

Having said that, it would be nice to have an option to configure a timeout which make the task fail if no permits are available when it expires.

Internally it would be using the Semaphore tryAcquire() method. And the api to add could be:

ExecutorTool.newSempahoreVirtualExecutor(10,  Duration.ofSeconds(10));

@maxxedev if you think it is a nice feature, I am willing to contribute it.

maxxedev commented 4 months ago

Sounds good. Please open a pull request

JordiMartinezVicent commented 3 months ago

@maxxedev I have just opened the PR: https://github.com/thunkware/virtual-threads-bridge/pull/22