Reputation: 7524
Scala has foreach construct to install callback on a Future:
myFuture foreach{
//computation
}
Initially there was onSuccess for same purpose.
onSuccess seems to be a better logical name(do this when future is complete). Why this name 'foreach' then? Does it represent something in context of callbacks which onSuccess is missing?
Upvotes: 0
Views: 285
Reputation: 44992
The only difference between foreach
and onComplete
seems to be that foreach
requires total functions as argument.
The onComplete
was deprecated in 2.12.0
. The named reasons were:
for
-comprehensionsLink: Deprecations: onSuccess and onFailure.
I'm not sure what to think about this argumentation. For example, there are quite a few redundant methods on Option
, couldn't we just remove all but one, and retain only fold
?
Upvotes: 2