Making asynchrounous wait with timeout | Sololearn: Learn to code for FREE!


Making asynchrounous wait with timeout

What is a good way to make an asynchronous wait list with timeout in Kotlin? Take for example an asynchrounous semaphore where we have 2 methods: Acquire - which will give an unit if available asynchrounously or wait for it during a given timeout. Release - which will give back the units and if there are anyone waiting for units give them so the Future returned by Acquire is successfully completed. So on the Acquire method I'll have 2 paths: - A happy path which will immediately return a completed future when there are units. - The path where it will be waiting for an unit. On the last path I'm creating a future and adding it to a queue and launching a coroutine to remove it from the list after the timeout and if it wasn't completed already. All of this inside a synchrounized block where the launched block will also have a synchronized block to test if it still on the queue . My question is if this is a good way of doing it.

7/10/2019 2:11:44 PM


0 Answers

New Answer