-
Notifications
You must be signed in to change notification settings - Fork 136
Acting on Futures (actOnFutures operator)
johnmcclean-aol edited this page Oct 13, 2015
·
6 revisions
The actOnFutures Operator ensures that the next operation is performed directly on the Stream of underlying Futures. The standard behaviour is act on results.
The normal behaviour of zipWithIndex is to act on the result of the previous stage.
LazyFutureStream.of("a","b","c","d")
.zipWithIndex()
.forEach(System.out::println)
["a",1l]
["b",2l]
["c",3l]
["d",4l]
If the values are not already present, but computed or loaded asyncrhonously then completion order will determine index assigned to each result.
new LazyReact().react(()->load("a"),()->load("b"),()->load("c"),()->load("d"))
.zipWithIndex()
.forEach(System.out::println)
["c",1l] <-- c completes first
["b",2l] <-- b completes second
["a",3l] <-- a completes third
["d",4l] <-- d completes fourth
When actOnFutures is used the index represents the index of the future task (and therefore the original order, or the order of the Futures input into that stage).
new LazyReact().react(()->load("a"),()->load("b"),()->load("c"),()->load("d"))
.actOnFutures()
.zipWithIndex()
.forEach(System.out::println)
["c",3l] <-- c completes first
["b",2l] <-- b completes second
["a",1l] <-- a completes third
["d",4l] <-- d completes fourth
To be completed...
oops - my bad