Skip to content

Instantly share code, notes, and snippets.

@olbpetersson
Last active December 5, 2017 17:14
Show Gist options
  • Save olbpetersson/2e693f66194d55e99e6ff62a4f5e7f40 to your computer and use it in GitHub Desktop.
Save olbpetersson/2e693f66194d55e99e6ff62a4f5e7f40 to your computer and use it in GitHub Desktop.
/* Synchronously prints
main
Current thread: main
hello, world!
Current thread: main
hello
Current thread: main
world
In about 15 seconds */
@Override
public void run(String... args) throws Exception {
// Check Hooks.
System.out.println(Thread.currentThread().getName());
Mono<String> helloWorld = Mono.just("hello, world!");
helloWorld.subscribe((x) -> {
this.printStringWithTimeout(x, 5000);
});
Flux<String> fluxHelloWorld = Flux.just("hello", "world");
fluxHelloWorld.subscribe((x) -> {
this.printStringWithTimeout(x, 5000);
});
}
public void printStringWithTimeout(String string, long timeoutMs) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Current thread: " + Thread.currentThread().getName());
System.out.println(string);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment