Futures in Scala Protips (part 6): Cancellation & Thread.interrupt()
Explains why Scala Futures are not cancellable by design and demonstrates how to implement interruptible/cancellable Future logic.
Viktor Klang is a software engineer specializing in developer experience, API design, software architecture, and concurrent and distributed systems. With over 20 years of experience, he has contributed to major language standard libraries, open-source projects, and scalable systems used by large global companies.
10 articles from this blog
Explains why Scala Futures are not cancellable by design and demonstrates how to implement interruptible/cancellable Future logic.
Explains advanced Scala Future techniques using transform and Try for more efficient concurrent programming transformations.
Explains Scala's BlockContext for managing thread blocking, including how to prohibit blocking in specific scopes.
Explains why to use Future.successful over Future.apply for performance when creating Scala Futures with known values.
Explains a common mistake when using Scala Futures in for-comprehensions and provides a solution to ensure parallel execution.
Explores best practices for managing ExecutionContext in Scala Futures, covering component design patterns for controlling asynchronous execution.
Explains the advanced Async Continuation Passing Style (ACPS) technique and improved promise linking in Scala 2.12 Futures.
Explains the removal of sun.misc.Unsafe from Scala's Future implementation in version 2.12, replaced with AtomicReference for better compatibility.
Explores improvements to ExecutionContext and BlockContext in Scala 2.12's Future API, focusing on deprecations, new features, and thread management.
Explores missing utility methods in Scala Futures, specifically Future.unit and Future.never, discussing their implementation and use cases.