1
- FIXME: add a description
1
+ The integrator function can pass data downstream using the push method
2
+ In return, the stream should return a result indicating whether it accepted the latest value.
2
3
3
- // If you want to factorize the description uncomment the following line and create the file.
4
- //include::../description.adoc[]
4
+ Ignoring the value returned by `Downstream.push` might lead to inconsistent behavior of the integrator.
5
5
6
6
== Why is this an issue?
7
7
@@ -18,14 +18,39 @@ FIXME: remove the unused optional headers (that are commented out)
18
18
19
19
[source,java,diff-id=1,diff-type=noncompliant]
20
20
----
21
- FIXME
21
+ Gatherer.ofSequential(
22
+ () -> new AtomicInteger(100),
23
+ (state, element, downstream) -> {
24
+ int newState = state.addAndGet(element);
25
+ downstream.push(newState); // Noncompliant: ignoring return value
26
+ return true;
27
+ });
22
28
----
23
29
24
30
==== Compliant solution
25
31
26
32
[source,java,diff-id=1,diff-type=compliant]
27
33
----
28
- FIXME
34
+ Gatherer.ofSequential(
35
+ () -> new AtomicInteger(100),
36
+ (state, element, downstream) -> {
37
+ int newState = state.addAndGet(element);
38
+ return downstream.push(newState); // Compliant
39
+ });
40
+ ----
41
+
42
+ [source,java,diff-id=1,diff-type=compliant]
43
+ ----
44
+ Gatherer.ofSequential(
45
+ () -> new AtomicInteger(100),
46
+ (state, element, downstream) -> {
47
+ int newState = state.addAndGet(element);
48
+ if (downstream.push(newState)) {
49
+ // Do something to handle this specific case
50
+ return false;
51
+ }
52
+ return true;
53
+ });
29
54
----
30
55
31
56
//=== How does this work?
0 commit comments