Created
May 7, 2022 10:54
-
-
Save ahndmal/84df48a0f7fd37e328bf29742ef02c65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class IntervalMessageProducer { | |
public static Flux<String> produce(int c) { | |
return produce().take(c); | |
} | |
public static Flux<String> produce() { | |
return doProduceCountAndStrings().map(CountAndString::message); | |
} | |
private static Flux<CountAndString> doProduceCountAndStrings() { | |
var counter = new AtomicLong(); | |
return Flux // | |
.interval(Duration.ofSeconds(1)) // <1> | |
.map(i -> new CountAndString(counter.incrementAndGet())); // | |
} | |
} | |
record CountAndString(String message, long count) { | |
CountAndString(long count) { | |
this("# " + count, count); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment