Skip to content

Instantly share code, notes, and snippets.

View olbpetersson's full-sized avatar
🥞
I eat pancakes.

Ola Petersson olbpetersson

🥞
I eat pancakes.
  • Meltwater
  • Gothenburg
View GitHub Profile
class ExampleWithChannelnstead {
private val logger = LoggerFactory.getLogger("test")
var nrOfReturnedMessages = AtomicInteger(0)
var nrOfProcessedMessages = AtomicInteger(0)
@UseExperimental(InternalCoroutinesApi::class)
fun receiveMessages(channel: Channel<List<Message>>) = GlobalScope.launch {
supervisedLoop {
while (isActive) {
val messages = getMesagesFromSqs()
fun receiveMessages() = flow {
while(isActive) {
val messages = getMesagesFromSqs() // getMessages here takes 1 second
logger.info("Nr of received messages $nrOfReturnedMessages")
emit(messages)
}
}
}
suspend fun processMessage(flow: Flow<List<Message>>) {
do {
val items = get1000Items(lastEvaluatedKey)
items.forEach() {
httpClient.doCall()
}
lastEvaluatedKey = items.getLastEvaluatedKey()
} while(lastEvaluatedKey != null)
<!-- Seems like shouldDisplay() is evaluated two times in this scenario. Is there a way to cache the first evaluatio? -->
<div *ngIf="shouldDisplay()" >
This div is optional
</div>
<div>
This should always be shown
</div>
<div *ngIf="shouldDisplay()">
This div is also optional
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.1.0-M1</version>
<scope>test</scope>
</dependency>
@RestController
@RequestMapping("/hello")
public class HelloWorldController {
@Autowired
private HelloWorldService helloWorldService;
@GetMapping
public Mono<String> helloWorld() {
return helloWorldService.getHelloWorld();
@Configuration
public class WebConfiguration {
@Bean
RouterFunction<?> routes(HelloWorldService helloWorldService) {
// request.pathVariable holds path-variables
return RouterFunctions.route(
GET("func-hello"),
request -> ServerResponse.ok().body(helloWorldService.getHelloWorld(), String.class));
}
@Component
public class SpringReactiveApplicationCLR implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
//Executed when the spring boot application starts
}
}
mono.subscribe(new BaseSubscriber<String>() {
@Override
protected void hookOnNext(String value) {
...
}
});
/* Synchronously prints
main
Current thread: main
hello, world!
Current thread: main
hello
Current thread: main
world
In about 15 seconds */