On closer look, there might not be a leak in the Future-based implementation. The use of Future#onComplete is scarce, and only in places where either
the chain of promises cannot be compacted anyway, or
the Future originates from a Promise that is going to be completed promptly, as the use of Promise is just auxiliary during materialization of the program.
Fix the resource leak related to long chains of promises (as described in #46) in
Future
-based implementation.The problem is likely fixable by adding an extra level of indirection.
Add tests that check that the number of allocated promises remains constant for several use cases. (Depends on #70.)