Add future with timeout to scala.concurrent?

It would essentially require an always-on builtin clock (Akka Scheduler) alternatively augment the ExecutionContext contract to include the ability to do timeouts, having the default implementation delegating to the global clock.

But again, the danger is that there is no one-size fits all when it comes to clocks.

Sure, but having something is better than nothing so a sane default would be overall helpful (in my view)

2 Likes

That depends on whether it is possible to switch what people use without having them republishing their artifacts. Case in point—having a non-scalable clock would work in the small, but when everything is put together would lead to some horrible behavior at runtime (including, but not limited to, OOMEs)

2 Likes

Would it be possible in Scala 2.14, Scala 3?

That’s orthogonal. if a specific Clock is embedded in user code, then being able to switch it out if it has issues will be non-trivial.

That’s true, that’s why Java’s CompletableFuture does not have a timeout method on it too

You can easily implemented it with hashwheeledtimer,if you don’t like the akka one

Or Deferred?