This file contains 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
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() |
This file contains 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
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>>) { |
This file contains 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
do { | |
val items = get1000Items(lastEvaluatedKey) | |
items.forEach() { | |
httpClient.doCall() | |
} | |
lastEvaluatedKey = items.getLastEvaluatedKey() | |
} while(lastEvaluatedKey != null) |
This file contains 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
<!-- 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 |
This file contains 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
<dependency> | |
<groupId>org.junit.jupiter</groupId> | |
<artifactId>junit-jupiter-engine</artifactId> | |
<version>5.1.0-M1</version> | |
<scope>test</scope> | |
</dependency> |
This file contains 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
@RestController | |
@RequestMapping("/hello") | |
public class HelloWorldController { | |
@Autowired | |
private HelloWorldService helloWorldService; | |
@GetMapping | |
public Mono<String> helloWorld() { | |
return helloWorldService.getHelloWorld(); |
This file contains 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
@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)); | |
} |
This file contains 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
@Component | |
public class SpringReactiveApplicationCLR implements CommandLineRunner { | |
@Override | |
public void run(String... args) throws Exception { | |
//Executed when the spring boot application starts | |
} | |
} |
This file contains 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
mono.subscribe(new BaseSubscriber<String>() { | |
@Override | |
protected void hookOnNext(String value) { | |
... | |
} | |
}); |
This file contains 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
/* Synchronously prints | |
main | |
Current thread: main | |
hello, world! | |
Current thread: main | |
hello | |
Current thread: main | |
world | |
In about 15 seconds */ |
NewerOlder