I think the problem is that in
alsoTo you use
seq instead of using the
Sink provided by
preMaterialize. From the
* Materializes this Sink, immediately returning (1) its materialized value, and (2) a new Sink
* that can be consume elements 'into' the pre-materialized one.
* Useful for when you need a materialized value of a Sink when handing it out to someone to materialize it for you.
* Note that the `ActorSystem` can be used as the `systemProvider` parameter.
b is the
first element of the resulting
pair after invoking
preMaterialize you are ignoring the
second element of the
pair which is the
Sink. Try the following instead:
Sink<String, CompletionStage<List<String>>> seq = Flow.<String>create().log("second").toMat(Sink.seq(), Keep.right());
Pair<CompletionStage<List<String>>, Sink<String, NotUsed>> pair = seq.preMaterialize(system);
CompletionStage<List<String>> b = pair.first();
CompletionStage<List<String>> a = Source.from(Arrays.asList("a", "b", "c"))
b.thenAccept(System.out::println).thenAccept( x -> System.out.println("B is done."));
[a, b, c]
[a, b, c]
B is done.